C Exercises: Read an amount and break the amount into smallest possible number of bank notes
C Basic Declarations and Expressions: Exercise-16 with Solution
Write a C program to read an amount (integer value) and break the amount into smallest possible number of bank notes.
Note: The possible banknotes are 100, 50, 20, 10, 5, 2 and 1.
C Code:
#include <stdio.h>
int main() {
int amt, total;
printf("Input the amount: ");
scanf("%d",&amt);
total = (int)amt/100;
printf("There are: ");
printf("\n%d Note(s) of 100.00\n", total);
amt = amt-(total*100);
total = (int)amt/50;
printf("%d Note(s) of 50.00\n", total);
amt = amt-(total*50);
total = (int)amt/20;
printf("%d Note(s) of 20.00\n", total);
amt = amt-(total*20);
total = (int)amt/10;
printf("%d Note(s) of 10.00\n", total);
amt = amt-(total*10);
total = (int)amt/5;
printf("%d Note(s) of 5.00\n", total);
amt = amt-(total*5);
total = (int)amt/2;
printf("%d Note(s) of 2.00\n", total);
amt = amt-(total*2);
total = (int)amt/1;
printf("%d Note(s) of 1.00\n", total);
return 0;
}
Sample Output:
Input the amount: 375 There are: 3 Note(s) of 100.00 1 Note(s) of 50.00 1 Note(s) of 20.00 0 Note(s) of 10.00 1 Note(s) of 5.00 0 Note(s) of 2.00 0 Note(s) of 1.00
Flowchart:
C Programming Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C program to calculate the distance between the two points.
Next: Write a C program to convert a given integer (in seconds) to hours, minutes and seconds.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
C Programming: Tips of the Day
Static variable inside of a function in C
The scope of variable is where the variable name can be seen. Here, x is visible only inside function foo().
The lifetime of a variable is the period over which it exists. If x were defined without the keyword static, the lifetime would be from the entry into foo() to the return from foo(); so it would be re-initialized to 5 on every call.
The keyword static acts to extend the lifetime of a variable to the lifetime of the programme; e.g. initialization occurs once and once only and then the variable retains its value - whatever it has come to be - over all future calls to foo().
Ref : https://bit.ly/3fOq7XP
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework