Introduction

     Understanding the intricacies of handling currency denominations is crucial in various programming scenarios. In this blog post, we delve into a simple C program that calculates the breakdown of currency notes for a given amount. The code provides insight into the logic behind counting the number of notes for different denominations.  


Code

    
     
        // Program for currency denomination
        #include<stdio.h>
        #include<conio.h>
        void main()
        {
        int a[10]={2000,500,100,50,20,10,5,2,1};
        int i,m,temp;
        clrscr();
        printf("enter the amount:");
        scanf("%d",&m);
        temp=m;
        for(i=0;i<9;i++)
        {
        printf("\n%d notes is:%d",a[i],temp/a[i]);
        temp=temp%a[i];
        }
        getch();
        }
    


Output

    
        // Output
    enter the amount:2135
    2000 notes is:1
    500 notes is:0
    100 notes is:1
    50 notes is:0
    20 notes is:1
    10 notes is:1
    5 notes is:1
    2 notes is:0
    1 notes is:0
       




Explanation

 1. Header Files: 
     The program includes the header for standard input/output and for console input/output. Note that is     not part of the standard C library and might not be available on all compilers. 
 2.Main Function: 
    The main function is the starting point of execution. An array a is declared to represent various     currency denominations. The variable m stores the amount entered by the user, and temp is a temporary     variable used for calculations. 
 3. User Input: 
     The user is prompted to enter the amount, and the input is captured using scanf. 
 4. Note Calculation: 
     A loop iterates through the array a to calculate the number of notes for each denomination. The result     is printed, and the remaining amount is updated. 
 5. Display Results:
     The breakdown of notes is displayed using printf. 
 6. End of Program: 
     The program waits for a key press using getch() before closing the console.


Conclusion

     This C program demonstrates a simple yet practical application of structures and conditional statements to convert time from the 24-hour format to the 12-hour format. Understanding such programs not only enhances programming skills but also provides insights into real-world applications where time representations vary based on conventions. The ability to manipulate time formats is essential in various programming scenarios, making this example valuable for learners and developers alike.