- Write a C program to accept an amount and find number of notes.
Required Knowledge
- C printf and scanf functions
- For loop in C
- Arrays in C
Starting from the highest denomination note, we will try to accommodate as many notes possible.
For example, let amount is A and current note is N, then number of notes is A/N and remaining amount is A%N.Let’s say A = 450 and N = 100, then number of 100 notes is 450/100 = 4 and remaining amount is 450%100 = 50.
We will repeat this process for all notes in decreasing order.
C program to accept an amount and find number of notes

/**
* C program to accept an amount and count number of notes
*/
#include <stdio.h>
int main() {
int number, i;
int notes[7] = {1000, 500, 100, 50, 10, 5, 1};
int noteCounter[7] = {0};
/*
* Take a number as input from user
*/
printf("Enter a Number\n");
scanf("%d", &number);
for(i = 0; i < 7; i++) {
if(number >= notes[i]){
noteCounter[i] = number/notes[i];
number = number - noteCounter[i]*notes[i];
}
}
/* Print notes */
printf("Currency Count\n");
for(i = 0; i < 7; i++){
if(noteCounter[i] != 0){
printf("%d %d\n", notes[i], noteCounter[i]);
}
}
return 0;
}
Output
Enter a Number 868 Currency Count 500 1 100 3 50 1 10 1 1 3