Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Recursive Function help

zbmayzbmay Member Posts: 2
So I need help with my recursive function.
I have to do the following. Allow the user to input a number. After that the program is suppose to run in order to show how many different combinations a machine could walk a certain distance. The machine is allowed to walk 1,2,3 meters in order to get to the distance inputted by the user. So the machine 4 meters.
Output the following:

The robot can walk 4 meters in 7 ways
1 1 1 1
2 1 1
1 2 1
1 1 2
2 2
1 3
3 1

My code so far is
int walk(int distance);
int combination (int a,int count);
int d,count,answer;
printf("A robot can walk 1,2 or 3 meter at a time
printf("This program will give all the possible combinations the
robot can walk
How far would you like the robot to walk? ");
if (d<1)<br /> printf("
A robot can not walk a negitive distance
count = walk(d);
printf("The robot can walk %d meters in %d ways.
Would you like to run program again? (0=No 1=Yes)");
int walk(int distance)
switch (distance){
case 1:
return 1;
case 2:
return 2;
case 3:
return 4;
return walk(distance-1)+walk(distance-2)+walk(distance-3);
int combination(int a,int count)
if (count <=1){<br /> printf("%d",a);
return a;
But i am having a bunch of trouble with the recursive function that shows the different combinations
Sign In or Register to comment.