Advertisement
alamin54017

Coin Changing in C

Jun 16th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include<stdio.h>
  2. void coinchange(int c[],int n,int s)
  3. {
  4.     int i,num;
  5.     while(s>0){
  6.         for(i=0;i<n;i++){
  7.             if(c[i]<=s) break;
  8.         }
  9.         num=s/c[i];
  10.         printf("%d * %d = %d\n",c[i],num,c[i]*num);
  11.         s=s-(num*c[i]);
  12.     }
  13. }
  14. int main()
  15. {
  16.     int c[6]={100,50,20,10,5,1};
  17.     int n=6;
  18.     printf("Enter your money: ");
  19.     int x;
  20.     scanf("%d",&x);
  21.     coinchange(c,n,x);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement