By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,819 Members | 1,173 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,819 IT Pros & Developers. It's quick & easy.

Problem Printing with a recursive function

P: 1
Hi, I'm having some trouble with a recursive function.
The function is written in C++.

The function is suppose to tell you how many paths there are on a grid. You are only allowed to move north and east. So say that the finishing cordinates are x=3,y=1 and the starting point is x=0,y=0. When using recursion, it will tell you how many paths there are(in this case 4). I managed to get the function to tell me how many paths there are in the function, but I'm totally out of ideas on how to print the individual paths(one path being NEEE,another EENE) and so on. I've included the code for my function. Thank you for your time.

Expand|Select|Wrap|Line Numbers
  1. int path(int maxEast,int maxNorth)
  2. {
  3.     int r1;
  4.     int r2;
  6.     if((maxEast > 3) || (maxNorth > 1))
  7.     {
  8.           return 0;
  9.     }
  11.     if((maxEast==3) && (maxNorth==1))
  12.     {
  13.          return 1;
  14.     }
  16.     r1=path(maxEast+1,maxNorth);
  17.     r2=path(maxEast,maxNorth+1);
  19.     return(r1+r2);    
  20. }
Mar 17 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.