Skip to content

Commit 5b8aa22

Browse files
committed
Added A new problem of minimum coins in Greedy Algo
1 parent e6d0e2e commit 5b8aa22

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Greedy/MinimumCoins/mincoins.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
// All denominations of Indian Currency
5+
int deno[] = {1, 2, 5, 10, 20, 50, 100, 500, 1000};
6+
int n = sizeof(deno)/sizeof(deno[0]);
7+
8+
// Driver program
9+
void findMin(int V)
10+
{
11+
// Initialize result
12+
vector<int> ans;
13+
14+
// Traverse through all denomination
15+
for (int i=n-1; i>=0; i--)
16+
{
17+
// Find denominations
18+
while (V >= deno[i])
19+
{
20+
V -= deno[i];
21+
ans.push_back(deno[i]);
22+
}
23+
}
24+
25+
// Print result
26+
for (int i = 0; i < ans.size(); i++)
27+
cout << ans[i] << " ";
28+
}
29+
30+
// Driver program
31+
int main()
32+
{
33+
int n;
34+
cin>>n;
35+
cout << "Following is minimal number of change for " << n << " is ";
36+
findMin(n);
37+
return 0;

0 commit comments

Comments
 (0)