Created
July 23, 2017 14:54
-
-
Save kt-aakash/01695524ae96f5ffd5841065df89cd57 to your computer and use it in GitHub Desktop.
cs50 pset1 greedy.c
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
#include<stdio.h> | |
#include<cs50.h> | |
int penny(int n, int temp) | |
{ | |
if(n>=25){ | |
n -= 25; | |
temp++; | |
} | |
else if(n>=10 && n<25){ | |
n -= 10; | |
temp++; | |
} | |
else if(n>=5 && n<10){ | |
n -= 5; | |
temp++; | |
} | |
else if(n>=1 && n<10){ | |
n -= 1; | |
temp++; | |
} | |
if(n>0) | |
{ | |
//printf("n=%d/n",n); | |
//printf("temp=%d/n",temp); | |
return(penny(n, temp)); | |
} | |
return temp; | |
} | |
int main(void) | |
{ | |
float change; | |
int n, count=0; | |
do{ | |
printf("O hai! How much change is owed?\n"); | |
change = get_float(); | |
}while(change<0); | |
n = (int)(change*100)%100; | |
count = penny(n, count); | |
printf("%d\n",count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment