Skip to content

Instantly share code, notes, and snippets.

@Praful932
Created June 19, 2019 10:26
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 Praful932/42ff3ec3dbac3804582707788dab7d39 to your computer and use it in GitHub Desktop.
Save Praful932/42ff3ec3dbac3804582707788dab7d39 to your computer and use it in GitHub Desktop.
//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