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

Comments

Popular posts from this blog

Q: The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate area & perimeter of the rectangle and area & circumference of the circle.

Q: If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. (Hint: Use the modulus operator ‘%’)