Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //1,2,5,10,20,50
- int main()
- {
- int amount;
- int fiftytk=0,twentytk=0,tentk=0,fivetk=0,twotk=0,onetk=0;
- printf("Enter your Taka for CHANGE:\t");
- scanf("%d",&amount);
- int original_am=amount;
- //fiftycheck
- while(amount>=50)
- {
- amount=amount-50;
- fiftytk++;
- }
- //twentycheck
- while(amount>=20)
- {
- amount=amount-20;
- twentytk++;
- }
- //tencheck
- while(amount>=10)
- {
- amount=amount-10;
- tentk++;
- }
- //fivecheck
- while(amount>=5)
- {
- amount=amount-5;
- fivetk++;
- }
- //twocheck
- while(amount>=2)
- {
- amount=amount-2;
- twotk++;
- }
- //FINALLY onecheck
- while(amount>=1)
- {
- amount=amount-1;
- onetk++;
- }
- if(amount==0)
- {
- printf("For %d Greedy is \nfiftytk=%d,\ntwentytk=%d,\ntentk=%d,\nfivetk=%d,\ntwotk=%d,\nonetk=%d;",original_am,fiftytk,twentytk,tentk,fivetk,twotk,onetk);
- }
- else printf("Greedy FAILED %d",amount);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement