Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Coin{
- float value;
- int count;
- };
- void greedyKnapsackMoney(Coin c[], int n, float amount)
- {
- int i;
- float currentAmount=0;
- for(i=0;i<n;i++)
- {
- if(currentAmount+c[i].value<= amount)
- {
- currentAmount = currentAmount+c[i].value;
- c[i].count++;
- i--;
- }
- }
- cout << "\n\n----------------------"<<endl;
- for(i=0; i<n; i++)
- {
- if(c[i].count != 0)
- {
- if(c[i].value >= 1)
- {
- cout << " " << c[i].value << " Taka Coin Quantity--> " << c[i].count <<endl;
- }
- else
- {
- cout << " " << c[i].value << " Poisa Coin Quantity--> " << c[i].count <<endl;
- }
- }
- }
- }
- int main()
- {
- float amount;
- cout << "Input Amount: ";
- cin >> amount;
- float coinValue[8] = {5,2,1,0.50,0.25,0.10,0.05,0.01};
- Coin c[8];
- for(int i=0; i<8; i++)
- {
- c[i].value = coinValue[i];
- c[i].count = 0;
- }
- greedyKnapsackMoney(c,8,amount);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment