#include<bits/stdc++.h>
using namespace std;
int ways(int coin[], int n, int tk)
{
if(tk == 0)
return 1;
if(tk < 0)
return 0;
if(n <= 0 && tk >= 1)
return 0;
return ways(coin, n-1, tk) + ways(coin, n, tk - coin[n-1]);
}
int main()
{
int n, i, tk;
cout << "Enter Coin Number :: ";
cin >> n;
int coin[n];
cout << "Enter Each Coin Value :: ";
for(i=0;i<n;i++)
cin >> coin[i];
cout << "Enter Total Amount :: ";
cin >> tk;
cout << "\nNumber Of Ways Of Coin Change :: " << ways(coin, n, tk) << "\n";
return 0;
}
using namespace std;
int ways(int coin[], int n, int tk)
{
if(tk == 0)
return 1;
if(tk < 0)
return 0;
if(n <= 0 && tk >= 1)
return 0;
return ways(coin, n-1, tk) + ways(coin, n, tk - coin[n-1]);
}
int main()
{
int n, i, tk;
cout << "Enter Coin Number :: ";
cin >> n;
int coin[n];
cout << "Enter Each Coin Value :: ";
for(i=0;i<n;i++)
cin >> coin[i];
cout << "Enter Total Amount :: ";
cin >> tk;
cout << "\nNumber Of Ways Of Coin Change :: " << ways(coin, n, tk) << "\n";
return 0;
}
Comments
Post a Comment