Find Minimum Number Of Coins
Find Minimum Number Of Coins
/*******************************************************************/
// Simple C code to Find Minimum Number Of Coins #include <stdio.h> #define COINS 9 #define MAX 20 int coins[COINS] = {1, 2, 5, 10,20,50,100,200,1000}; void findMinCoin(int cost) { int coinList[MAX]={0}; int ii,k=0; for( ii = COINS-1; ii>=0; ii--) { while(cost >= coins[ii]) { cost -= coins[ii]; coinList[k++]=coins[ii]; //add coin in the list } } for(ii=0; ii<k;ii++) { printf(" %d\t",coinList[ii]); // print } return; } int main(void) { int val=986; // input value findMinCoin(val); return 0; } |
Thanks for reading Guys. If you have any doubt, please write the comment below. Keep Learning. Happy coding
Connect with me on Linkedin ->MUNISH BHARDWAJ
Comments
Post a Comment