C program to count total number of notes in entered amount

Introduction

C program to enter month number and print number of days in month.. I have used DEV-C++ compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
 
int main()
{
    int amount;
        
    int note1, note2, note5, note10, note20, note50, note100, note500;
    
    note1 = note2 = note5 = note10 = note20 = note50 = note100 = note500 = 0;     
    
    printf("Enter amount: ");
    scanf("%d", &amount); 
 
    if(amount >= 500)
    {
        note500 = amount/500;
        amount -= note500 * 500;
    }
    if(amount >= 100)
    {
        note100 = amount/100;
        amount -= note100 * 100;
    }
    if(amount >= 50)
    {
        note50 = amount/50;
        amount -= note50 * 50;
    }
    if(amount >= 20)
    {
        note20 = amount/20;
        amount -= note20 * 20;
    }
    if(amount >= 10)
    {
        note10 = amount/10;
        amount -= note10 * 10;
    }
    if(amount >= 5)
    {
        note5 = amount/5;
        amount -= note5 * 5;
    }
    if(amount >= 2)
    {
        note2 = amount /2;
        amount -= note2 * 2;
    }
    if(amount >= 1)
    {
        note1 = amount;
    }
 
    printf("Total number of notes = \n");
    printf("500 = %d\n", note500);
    printf("100 = %d\n", note100);
    printf("50 = %d\n", note50);
    printf("20 = %d\n", note20);
    printf("10 = %d\n", note10);
    printf("5 = %d\n", note5);
    printf("2 = %d\n", note2);
    printf("1 = %d\n", note1);
 
    return 0;
}

Result

C program to count total number of notes in entered amount
C program to count total number of notes in entered amount

2 thoughts on “C program to count total number of notes in entered amount”

  1. try this faster and efficient code :

    void Min_Notes(int n)
    {
    int amt=n;
    printf(“Minimum notes required to pay %d is : \n”,amt);
    while(amt!=0)
    {
    if(amt/2000>=1)
    {
    printf(“%d Rs 2000 notes \n”,amt/2000);
    amt%=2000;
    }
    else if(amt/500>=1)
    {
    printf(“%d Rs 500 notes \n”,amt/500);
    amt%=500;
    }
    else if(amt/200>=1)
    {
    printf(“%d Rs 200 notes \n”,amt/200);
    amt%=200;
    }
    else if(amt/100>=1)
    {
    printf(“%d Rs 100 notes \n”,amt/100);
    amt%=100;
    }
    else if(amt/50>=1)
    {
    printf(“%d Rs 50 notes \n”,amt/50);
    amt%=50;
    }
    else if(amt/20>=1)
    {
    printf(“%d Rs 20 notes \n”,amt/20);
    amt%=20;
    }
    else if(amt/10>=1)
    {
    printf(“%d Rs 10 notes \n”,amt/10);
    amt%=10;
    }
    else if(amt/5>=1)
    {
    printf(“%d Rs 5 coins \n”,amt/5);
    amt%=5;
    }
    else if(amt/2>=1)
    {
    printf(“%d Rs 2 coins \n”,amt/2);
    amt%=2;
    }
    else
    {
    printf(“%d Rs 1 coins “,amt/1);
    amt=amt%1;
    }
    }
    }

    Reply

Leave a Comment