Last active
September 20, 2017 07:35
-
-
Save snadahalli/ba3675bad57dae3341713c23161ca318 to your computer and use it in GitHub Desktop.
A simple solution for Change-making problem based on greedy method.
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> | |
int main () { | |
int num_denominations, coin_list[100], use_these[100], i, owed; | |
printf("Enter number of denominations : "); | |
scanf("%d", &num_denominations); | |
printf("\nEnter the denominations in descending order: "); | |
for(i=0; i< num_denominations; i++) { | |
scanf("%d", &coin_list[i]); | |
// use_these[i] = 0; | |
} | |
printf("\nEnter the amount owed : "); | |
scanf("%d", &owed); | |
for(i=0; i < num_denominations; i++) { | |
use_these[i] = owed / coin_list[i]; | |
owed %= coin_list[i]; | |
} | |
printf("\nSolution: \n"); | |
for(i=0; i < num_denominations; i++) { | |
printf("%dx%d ", coin_list[i], use_these[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment