Gidhub BE Developer

반올림(Rounds)

2018-09-16
goodGid

To Do

  • 프로그래밍할 때 유용하게 쓰일 반올림 처리 코드에 대해 알아보자.

Problem

Problem URL : 2909. 반올림 처리


Code

int C, K, t = 1;
int main() {
	scanf("%d %d", &C, &K);
	for (int i = 0; i < K; i++) t *= 10;
	K = t / 10;
	printf("%d\n", (C + (K * 5)) / (K * 10) * (K * 10));

	return 0;
}

/*
K자리 의미는 
1일 때는 10단위로
2일 때는 100단위로
n일 때는 pow(10,n)이다.
*/

Input : 123 1 
Output : 120

Input : 123 2
Output : 100

Reivew

  • 반올림 하는 간결한 코드

Index