In this tutorial you will learn about the C Program to find Total Notes in a Given Amount and its application with practical example.
C Program to find Total Notes in a Given Amount
In this tutorial, we will learn to create a C program that will find Total Notes in a Given Amount using C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Conditional Statements in C programming.
- Arithmetic operations in C Programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input amount from the user. 3. Using the <strong>mathematical expressions </strong>to find the number of notes. 4. Printing the notes to the user. 5. End the Program. |
Find Total Notes in a Given Amount:-
In this program, we will take the input amount of currency from the user. Then we will pass that amount to the for loop and conditional statements to find the number of notes for that amount. At last, we will print the number of notes to the user.
With the help of the below program, we can convert days to weeks and years.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
/* C Program to find Total Notes in a Given Amount */ #include<stdio.h> int main() { //declaring the required variables for the program. int a[8] = {500, 100, 50, 20, 10, 5, 2, 1}; int Amount, i, flag; //Amount = it will hold the input amount from the user. //i = it will hold the integer value for the loop. //flag = it will hold the temporary value. /* Taking the Input amount number from user */ printf("\n Please Enter the Amount of Cash = "); scanf("%d", &Amount); //calculating the notes for the amount. flag = Amount; for(i = 0; i < 8; i++) { //Printing the amount in the form of notes. printf("\n %d Notes is = %d", a[i], flag / a[i]); flag = flag % a[i]; } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- Amount = it will hold the integer value for the input.
- i = it will hold the integer value for the controlling of the loop.
- flag = it will hold the temporary integer value.
Taking the input amount from the user.
Converting the notes for the amount.
Printing output.