728x90
달러를 동전으로 바꾸는 예제코드
포스트 난이도: HOO_Intern
# Example Codes
#include <stdio.h>
int main()
{
int cents, halfDollars, quarters, dimes, nickels, pennies;
printf("Enter change in [cents]: ");
scanf("%d",¢s);
printf("The change that has been entered is %d \n",cents);
halfDollars = (cents*2)/100;
printf("Half dollars: %d \n",halfDollars);
cents=cents - ((halfDollars*100)/2);
quarters=cents/25;
printf("Quarters: %d \n", quarters);
cents = cents - (quarters*25);
dimes = cents/10;
printf("Dimes: %d \n", dimes);
cents = cents - (dimes*10);
nickels = cents/5;
printf("Nickels: %d \n", nickels);
cents = cents - (nickels*5);
pennies = cents;
printf("Pennies %d \n", pennies);
printf("Posted by HOO.");
return 0;
}
Enter change in [cents]: 1377
The change that has been entered is 1377
Half dollars: 27
Quarters: 1
Dimes: 0
Nickels: 0
Pennies 2
Posted by HOO.
728x90
'C and C++ > C and C++ Examples' 카테고리의 다른 글
[C Examples] GPA 계산기 예제코드: if(), else if() (0) | 2023.02.17 |
---|---|
[C Examples] 7 Digit ISSN, 8번째 숫자 산출하기 예제코드: if(), else(), %d (0) | 2023.02.15 |
[C Examples/Q&A] 체질량 지수(BMI) 계산하는 예제코드: if, else if, && (0) | 2023.02.07 |
[C Examples] Circle area, circumference of circle 계산기 (0) | 2023.01.31 |
[C Examples] 총 지불액 계산기(팁, 세금 포함): float, scanf, %.f (0) | 2023.01.30 |
댓글