Find Minimum Number Of Coins



Find Minimum Number Of Coins


Given a value Cost , if we want to make change for Cost  Rs, and we have infinite supply of each of the denominations in Indian currency, i.e., we have infinite supply of { 1, 2, 5, 10, 20, 50, 100, 200, 1000} valued coins/notes, what is the minimum number of coins and/or notes needed to make the change?



/*******************************************************************/
// 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