C Program To Compute Smallest Number of Notes That Will Combine To Give Rs N


Consider a currency system in which there are notes of seven denominations, namely, Re 1, Rs 2, Rs 5, Rs 10, Rs 50 and Rs 100. If a sum of Rs N is entered through the keyboard, write a C program to compute the smallest number of notes that will combine to give Rs N.

Related Read:
Basic Arithmetic Operations In C

Logic To Get Minimum Number of Notes To Represent The Amount

First we divide the user entered amount with the biggest denomination i.e., Rs 100. Next, if its divisible, then we subtract the number of Rs 100 currency notes we get by dividing the amount by 100. Next we check for the next biggest denomination Rs 50 and so on ..Rs 10, Rs 5, Rs 2 and Rs 1.

Source Code: C Program To Compute Smallest Number of Notes That Will Combine To Give Rs N

 
#include < stdio.h >

int main()
{
    int amount, temp;

    printf("Enter amount\n");
    scanf("%d", &amount);

    temp   = amount / 100;
    amount = amount - (temp*100);

    printf("%d   x 100 = %d\n", temp, (temp*100));

    temp   = amount / 50;
    amount = amount - (temp*50);

    printf("%d   x 50  = %d\n", temp, (temp*50));

    temp   = amount / 10;
    amount = amount - (temp*10);

    printf("%d   x 10  = %d\n", temp, (temp*10));

    temp   = amount / 5;
    amount = amount - (temp*5);

    printf("%d   x 5   = %d\n", temp, (temp*5));

    temp   = amount / 2;
    amount = amount - (temp*2);

    printf("%d   x 2   = %d\n", temp, (temp*2));

    temp   = amount / 1;
    amount = amount - (temp*1);

    printf("%d   x 1   = %d\n", temp, (temp*1));

    return 0;
}

Output 1:
Enter amount
123
1 x 100 = 100
0 x 50 = 0
2 x 10 = 20
0 x 5 = 0
1 x 2 = 2
1 x 1 = 1

Output 2:
Enter amount
2000
20 x 100 = 2000
0 x 50 = 0
0 x 10 = 0
0 x 5 = 0
0 x 2 = 0
0 x 1 = 0

Output 3:
Enter amount
123456
1234 x 100 = 123400
1 x 50 = 50
0 x 10 = 0
1 x 5 = 5
0 x 2 = 0
1 x 1 = 1

C Program To Compute Smallest Number of Notes That Will Combine To Give Rs N


[youtube https://www.youtube.com/watch?v=JMDLjs0eEZE]

YouTube Link: https://www.youtube.com/watch?v=JMDLjs0eEZE [Watch the Video In Full Screen.]


For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

Your email address will not be published. Required fields are marked *