jain12

Count number of ways to cover a distance

May 27th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.29 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int PrintCountRec(int dist){
  5.   if(dist<0)
  6.     return 0;
  7.   if(dist==0)
  8.     return 1;
  9.   return PrintCountRec(dist-3)+PrintCountRec(dist-2)+PrintCountRec(dist-1);
  10.   }
  11.  
  12.  int main(){
  13.    int dist =3;
  14.    cout<<PrintCountRec(dist);
  15.    return 0;
  16.    }
Add Comment
Please, Sign In to add comment