Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int amount,n,i,j;
- printf("Enter total amount: ");
- scanf("%d", &amount);
- printf("Enter number of different coins: ");
- scanf("%d", &n);
- int coin[n],count[n];
- printf("Enter the coin values: ");
- for(i=0;i<n;i++)
- {
- scanf("%d", &coin[i]);
- count[i]=0;
- }
- int amount1=amount;
- for(i=0;i<n;i++)
- {
- if(amount==0)
- {
- break;
- }
- if(amount>=coin[i])
- {
- count[i]=(amount/coin[i])+count[i];
- amount=amount%coin[i];
- for(j=i;j>=0;j--)
- {
- if(amount==0)
- {
- break;
- }
- count[i]=(amount/coin[j])+count[i];
- amount=amount%coin[j];
- }
- if(amount!=0 && count[i]>0)
- {
- count[i]=0;
- }
- }
- amount=amount1;
- }
- int min=amount1+1;
- for(i=0;i<n;i++)
- {
- if(count[i]<min && count[i]!=0)
- {
- min=count[i];
- }
- }
- printf("Minimum number of coin: %d", min);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement