text: Greedy Algorithm to find Minimum number of Coins | C program to find minimum number of denominations ; All denominations of Indian Currency ; Initialize result ; Traverse through all denomination ; Find denominations ; Print result ; Driver Code
code: #include <stdio.h> NEW_LINE #define COINS  9 NEW_LINE #define MAX  20 NEW_LINE 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 ] ; coinList [ k ++ ] = coins [ i ] ; } } for ( i = 0 ; i < k ; i ++ ) { printf ( " % d ▁ " , coinList [ i ] ) ; } return ; } int main ( void ) { int n = 93 ; printf ( " Following ▁ is ▁ minimal ▁ number " " of ▁ change ▁ for ▁ % d : ▁ " , n ) ; findMin ( n ) ; return 0 ; }