Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int n,tk,arr[100];
- int coinChange();
- int main()
- {
- printf("Number of coin type: ");
- scanf("%d",&n);
- int i;
- printf("Enter them one by one:\n");
- for(i=0;i<n;i++)
- scanf("%d",&arr[i]);
- printf("Amount you want to make using the coins: ");
- scanf("%d",&tk);
- int ans=0;
- ans=coinChange();
- printf("Ans: %d\n",ans);
- return 0;
- }
- int coinChange()
- {
- int i,j,x,y;
- int TB[tk+1][n];
- for(i=0;i<n;i++)
- TB[0][i]=1;
- for(i=1;i<=tk;i++)
- for(j=0;j<n;j++)
- {
- if((i-arr[j])>=0)
- x=TB[i-arr[j]][j];
- else x=0;
- if(j>=1)
- y=TB[i][j-1];
- else y=0;
- TB[i][j]=x+y;
- }
- return TB[tk][n-1];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement