Advertisement
kiwser

Coin change

Aug 7th, 2021
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int coin[] = {1,2,5,10};
  6.     int taka, count_c = 0;
  7.  
  8.     scanf("%d", &taka);
  9.  
  10.     for(int i = 3; i >= 0; i--){
  11.         int res = taka/coin[i];
  12.  
  13.         if(res){
  14.             printf("%d = %d\n", coin[i], res);
  15.         }
  16.  
  17.         count_c+=res;
  18.  
  19.         taka = taka-coin[i]*res;
  20.  
  21.         if(taka == 0)break;
  22.     }
  23.  
  24.     printf("Coin Count : %d\n", count_c);
  25.  
  26. }
  27.  
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement