Created
June 19, 2019 10:26
-
-
Save Praful932/42ff3ec3dbac3804582707788dab7d39 to your computer and use it in GitHub Desktop.
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
//greedy least no of coins for change | |
#include<stdio.h> | |
#include<cs50.h> | |
#include<math.h> | |
int main(void) | |
{ | |
float n; | |
int coin=0; | |
do | |
{ | |
n=get_float("Change owed: "); | |
}while(n<0); | |
n=round(n*100); | |
while(n>=25) | |
{ | |
n=round(n-25); | |
coin++; | |
} | |
while(n>=10) | |
{ | |
n=round(n-10); | |
coin++; | |
} | |
while(n>=5) | |
{ | |
n=round(n-5); | |
coin++; | |
} | |
while(n>=1) | |
{ | |
n=round(n-1); | |
coin++; | |
} | |
printf("%d\n",coin); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment