C Program to count the total number of notes in a given amount – In this distinct article, we will describe the multiple ways to count the total number of notes in a given amount in C programming.
The ways used to count the total number of notes in a given amount in C programming are as follows:
- Using Standard Method
- Using User-Defined Function
- Using Pointers
As we all know, in cash bundles, several notes make up a stipulated amount of money necessary for the person concerned.
In the same way, this blog talks about the multitude of ways to count the number notes present in a given amount. A single base of note is multiplied several times in a bundle.
C program to count the total number of notes in a given amount. Here is the complete code with sample outputs and example programs, do check it out here. For more C beginner programs you can check out here.
Thus, the several methods with which the notes in a given amount is calculated in C programming are as follows:
Using Standard Method
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 |
#include <stdio.h> int main() { int a[8]={500,100,50,20,10,5,2,1},m,temp,i; printf("Enter the amount:"); scanf("%d",&m); temp=m; for(i=0;i<8;i++) { printf("\n%d notes is:%d",a[i],temp/a[i]); temp=temp%a[i]; } } |
1 2 3 4 5 6 7 8 9 10 |
Enter the amount:3456 500 notes is:6 100 notes is:4 50 notes is:1 20 notes is:0 10 notes is:0 5 notes is:1 2 notes is:0 1 notes is:1Press any |
Using User-Defined Function
1) Read the entered amount and put it in the variable m.
2) The user-defined function denomination will divide the amount in to 500,100,50,20,10,5,2,1 rupees notes.
Int array a[8]={500,100,50,20,10,5,2,1}.
temp=amount.
for loop iterates from i=0 to 7 ,
quotient of temp/a[i] ,represents no.of a[i] notes in the given amount.
temp=remainder of temp/a[i].
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 29 |
#include <stdio.h> int a[8]={500,100,50,20,10,5,2,1}; void denomination(int m); int main() { int m; printf("Enter the amount:"); scanf("%d",&m); denomination(m); return 0; } void denomination(int m) { int temp,i; temp=m; for(i=0;i<8;i++) { printf("\n%d notes is:%d",a[i],temp/a[i]); temp=temp%a[i]; } } |
Output:
1 2 3 4 5 6 7 8 9 10 |
Enter the amount:56789 500 notes is:113 100 notes is:2 50 notes is:1 20 notes is:1 10 notes is:1 5 notes is:1 2 notes is:2 1 notes is:0 |
Using Pointers
1)Pass the addresses of the array a, m to the function denomination as denomination(&a,&m).
2)The pointer variable *a points the values of the array, *m points the value which is at the address &m.
3)temp=the value pointed by the pointer variable *m.
for loop iterates from i=0 to 7
no.of a[i] notes =quotient of temp/the value pointed by the pointer variable *(a+i).
temp=remainder of temp/a[i].
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 29 30 31 32 33 |
#include <stdio.h> #include <stdio.h> void denomination(int *a,int *m); int main() { int a[8]={500,100,50,20,10,5,2,1},m; printf("Enter the amount:"); scanf("%d",&m); denomination(a,&m); return 0; } void denomination(int *a,int *m) { int temp,i; temp=*m; for(i=0;i<8;i++) { printf("\n%d notes is:%d",*(a+i),temp/(*(a+i))); temp=temp%a[i]; } } |
1 2 3 4 5 6 7 8 9 10 |
Enter the amount:1025 500 notes is:2 100 notes is:0 50 notes is:0 20 notes is:1 10 notes is:0 5 notes is:1 2 notes is:0 1 notes is:0Press any |