Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Language/C/min_no_of_coins.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// C program to find minimum number of denominations in Indian Currency using greedy approach.
#include <stdio.h>
#define COINS 9
#define MAX 20

int coins[COINS] = { 1, 2, 5, 10, 20,
50, 100, 200, 2000 };

void findMin(int cost)
{
int coinList[MAX] = { 0 };
int i, k = 0;

for (i = COINS - 1; i >= 0; i--) {
while (cost >= coins[i]) {
cost -= coins[i];
// Add coin in the list
coinList[k++] = coins[i];
}
}

for (i = 0; i < k; i++) {
// Print
printf("%d ", coinList[i]);
}
return;
}

int main(void)
{
// input value
int n = 93;

printf("Following is minimal number"
"of change for %d: ",
n);
findMin(n);
return 0;
}