[백준] 2033번 : 반올림 - C

강재원·2022년 10월 18일
0

[코딩테스트] C/C++

목록 보기
124/200



https://www.acmicpc.net/problem/2033

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

int main() {
    int n;
    scanf("%d",&n);
    int t=1;
    int num=n;
    while(n>9){
        int a=n%10;
        if(a>=5){
            num+=(10-a)*t;
            n+=10;
        }
        else num-=a*t;
        t*=10;
        n/=10;
    }
    printf("%d",num);
}
profile
개념정리 & 문법 정리 & 알고리즘 공부

0개의 댓글