Created
November 14, 2016 22:34
-
-
Save devteampentagon/be21d498b13b5b3c6f19a7307b161adc to your computer and use it in GitHub Desktop.
Coin Change [Unlimited Coins]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main() | |
{ | |
int i,j; | |
int coinNumber; | |
int coinNumberStore[10]; | |
int coinChange[102]; | |
memset(coinChange,0,sizeof(coinChange)); | |
coinChange[0] = 1; | |
scanf("%d",&coinNumber); | |
for(i=1; i<=coinNumber; i++) | |
{ | |
scanf("%d",&coinNumberStore[i]); | |
} | |
for(i=1; i<=coinNumber; i++) | |
{ | |
for(j=0; j<=100; j++) | |
{ | |
if(coinChange[j]!=0) | |
{ | |
coinChange[j+coinNumberStore[i]] = coinChange[j] + coinChange[j+coinNumberStore[i]]; | |
} | |
} | |
} | |
///*** printing the CoinChange way Array ***/// | |
for(j=0; j<=100; j++) | |
{ | |
printf("coinChange[%d] = %d\n",j,coinChange[j]); | |
} | |
///*** if say highest way to give money ***/// | |
int MaxWayToGiveMoney = 0; | |
for(j=0; j<=100; j++) | |
{ | |
if(coinChange[j]>=MaxWayToGiveMoney) | |
MaxWayToGiveMoney = coinChange[j]; | |
} | |
printf("Max Way to Give Money = %d\n",MaxWayToGiveMoney); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Help