The Coin Change Problem

  • + 0 comments

    include

    include

    using namespace std;

    vector coinChangeGreedy(const vector& coins, int amount) { vector result(coins.size(),0); for(int i=coins.size()-1;i>=0;i--) { result[i] = amount/coins[i]; amount %= coins[i]; } return result; }

    int main() { vector coins = {1,5,10,25}; int amount =47;

    cout<<"Greedy Approach result :"<<endl;
    vector <int> resultgreedy = coinChangeGreedy(coins,amount);
    
    for(int i=0;i<resultgreedy.size();i++)
    {
        cout<<resultgreedy[i]<<" ";
    }
    cout<< endl;
    return 0;
    

    }