Skip to content

Instantly share code, notes, and snippets.

@cozyplanes
Created August 19, 2017 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cozyplanes/41c692438848918577d4dab4c6d3269e to your computer and use it in GitHub Desktop.
Save cozyplanes/41c692438848918577d4dab4c6d3269e to your computer and use it in GitHub Desktop.
Greedy Sort Algorithm 에시입니다.
int main(void) {
float amount = 0;
int cents = 0;
int count = 0;
int amount_left = 0;
int coin_values[] = {25, 10, 5, 1}; // an array of ints that hold the values of the coins in cents.
int i;
amount = .30;
cents = (int)round(amount * 100);
printf("%d", cents);
amount_left = cents;
for(i=0; i<4; i++) {
while(amount_left >= coin_values[i]) {
count++;
amount_left -= coin_values[i];
}
}
printf("You get %d coins\n", count);
}
@cozyplanes
Copy link
Author

Output

30You get 2 coins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment