jain12

Coin change problem by recursion

Jun 7th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int Count(int arr[],int n,int value){
  5.   if(value==0)
  6.     return 1;
  7.   if(value<0)
  8.     return 0;
  9.   if(n<=0)
  10.     return 0;
  11.   return Count(arr,n,value-arr[n-1])+Count(arr,n-1,value);
  12.   }
  13.  
  14. int main(){
  15.   int arr[] = {1,2,3};
  16.   int m = sizeof(arr)/sizeof(arr[0]);
  17.   cout<< Count(arr, m, 4);
  18.   return 0;
  19.   }
Add Comment
Please, Sign In to add comment