[C++] 프로그래머스 정수 부분

문제설명

실수 flo가 매개 변수로 주어질 때,
flo의 정수 부분을 return하도록 solution 함수를 완성해주세요.


제한사항

• 0 ≤ flo ≤ 100


입출력 예

flo result
1.42 1
69.32 69


풀이

주어진 실수에서 정수부분만 return하는 문제입니다. floor함수를 이용하여 정수부분만 return하도록 구현했습니다.

#include <string>
#include <vector>
#include <cmath>

using namespace std;

int solution(double flo) {
    int answer = 0;
    
    answer = floor(flo);
    
    return answer;
}


결과

코드 실행결과

Categories:

Updated:

Leave a comment