Tiny Star

๐Ÿ”“Codingtest/0๏ธโƒฃLv.0

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋‘ ์ˆ˜์˜ ๋‚˜๋ˆ—์…ˆ - Java

hymiel 2023. 6. 9. 19:54

2023๋…„ 06์›” 09์ผ ์š”์ผ

[๋ฌธ์ œ ์„ค๋ช…]

์ •์ˆ˜ num1๊ณผ num2๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, 

num1์„ num2๋กœ ๋‚˜๋ˆˆ ๊ฐ’์— 1,000์„ ๊ณฑํ•œ ํ›„ ์ •์ˆ˜ ๋ถ€๋ถ„์„ return ํ•˜๋„๋ก soltuion ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

 

[๋‚ด ํ’€์ด]

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int solution(int num1, int num2) {
    int answer = 0;
    if(0<num1<=100 && 0<num2<=100) {
        float n = (float) num1/num2 * 1000;
        answer = (int) n;
        
    }
    return answer;
}

์ผ๋‹จ num1,2์˜ ์กฐ๊ฑด์ด 0 ์ดˆ๊ณผ 100์ดํ•˜์˜ ์กฐ๊ฑด์ด ์žˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— if๋ฌธ์„ ์ด์šฉํ–ˆ๋‹ค.

 

float ํƒ€์ž… ๋ณ€์ˆ˜ n์„ ์„ ์–ธ, floatํƒ€์ž…์œผ๋กœ num1/num2 * 1000์˜ ๊ฐ’์„ ๋ฐ›์•˜๊ณ ,

n์˜ ๊ฐ’์€ int๋กœ ํ˜•๋ณ€ํ™˜์„ ํ•œ ๋’ค answer์— ์ž…๋ ฅ ํ›„ ๊ทธ ๊ฐ’์„ ๋ฆฌํ„ด์‹œ์ผฐ๋‹ค.