Created
August 19, 2017 05:19
-
-
Save cozyplanes/41c692438848918577d4dab4c6d3269e to your computer and use it in GitHub Desktop.
Greedy Sort Algorithm 에시입니다.
This file contains 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
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output