C# program to find the minimum number of currency notes which sum up to the given amount N, is given here. The quantity of each type of note for the amount is also shown.
Page content(s):
1. C# Program to Find the Minimum Number of Currency Notes to Make an Amount N
Code has been copied
/************************************************ alphabetacoder.com C# program to find the minimum number of currency notes which sum upto the given amount N *************************************************/ using System; namespace MinimumNotes { class Program { static void Main() { // declare variables int N, t, k, i; // declare an array to store different currency value int[] currency = {500, 200, 100, 50, 20, 10, 5, 2, 1}; // take input Console.Write("Enter an amount: "); N = Convert.ToInt32(Console.ReadLine()); // initialize t = 0; // new line Console.WriteLine(""); // count the total no of currency unit for (i = 0; i < currency.Length; i++) { k = N / currency[i]; // display result for current unit Console.WriteLine(currency[i] + " required: " + k); // add to counter t = t + k; // calculate remaining amount N = N - k * currency[i]; } //display total Console.WriteLine("\nMinimum no. of notes required: " + t); // wait for user to press any key Console.ReadKey(); } } }
Output
Enter an amount: 1725
500 required: 3
200 required: 1
100 required: 0
50 required: 0
20 required: 1
10 required: 0
5 required: 1
2 required: 0
1 required: 0
Minimum no. of notes required: 6