Q: Consider a currency system in which there are note of seven denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100. if a sum of Rs. N is entered through the keyboard, write a program to compute the smallest number of notes that will combine to give Rs N.
#include <stdio.h>
#include <math.h>
int main()
{
int x,a,b,c,d,e,f;
printf("enter total amount of money\n");
scanf("%d",&x);
/*floor fun is used to get significant value*/
a=floor(x/100);
b=floor((x%100)/50);
c=floor(((x%100)%50)/10);
d=floor((((x%100)%50)%10)/5);
e=floor(((((x%100)%50)%10)%5)/2);
f=floor(((((x%100)%50)%10)%5)%2);
printf("note of 100 = %d\nnote of 50 = %d\nnote of 10 = %d\nnote of 5 = %d\nnote of 2 = %d\nnote of 1 = %d\n",a,b,c,d,e,f);
return 0;
}
-----------------------------------------
output :
enter total amount of money
2000034
note of 100 = 20000
note of 50 = 0
note of 10 = 3
note of 5 = 0
note of 2 = 2
note of 1 = 0
#include <math.h>
int main()
{
int x,a,b,c,d,e,f;
printf("enter total amount of money\n");
scanf("%d",&x);
/*floor fun is used to get significant value*/
a=floor(x/100);
b=floor((x%100)/50);
c=floor(((x%100)%50)/10);
d=floor((((x%100)%50)%10)/5);
e=floor(((((x%100)%50)%10)%5)/2);
f=floor(((((x%100)%50)%10)%5)%2);
printf("note of 100 = %d\nnote of 50 = %d\nnote of 10 = %d\nnote of 5 = %d\nnote of 2 = %d\nnote of 1 = %d\n",a,b,c,d,e,f);
return 0;
}
-----------------------------------------
output :
enter total amount of money
2000034
note of 100 = 20000
note of 50 = 0
note of 10 = 3
note of 5 = 0
note of 2 = 2
note of 1 = 0
Comments
Post a Comment