Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A robot can take steps of 1,2,3 meters. Write a program that allows the shows al

ID: 3529617 • Letter: A

Question

A robot can take steps of 1,2,3 meters. Write a program that allows the shows all the possible steps the robot can take using recursive functions that will compute the number of combinations entered by the user.



I am using ANSI C and don't have a strong background of programs, so explinations would help out very much


Example


The user enters "5" for how many meters the robot walked


Answer:

To travel 5 meters: there are 13 possible combinations

11111

2111

1211

1121

1112

221

212

122

311

131

113

32

23

So i need the program to display all of this.

So far I have this for my program. It only tells how how many combinations there are and i am also not getting the right answer for my combinations. If I take away "walk(distance-3)" for the bottom part, my program works correctly. But that is combinations if the robot walks 2 meters not 3.



#include <stdio.h>

#include <stdlib.h>

int walk(int distance);

main()

{

int d,count;

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 ");

printf(" How far would you like the robot to walk? ");

scanf("%d",&d);

if (d<1)

printf(" A robot can not walk a negitive distance ");

else{

count = walk(d);

printf("The robot can walk %d meters in %d ways. ",d,count);

getchar();

getchar();

}

}

int walk(int distance)

{

if (distance<=2)

return distance;

else

{

return walk(distance-1)+walk(distance-2)+walk(distance-3);

}

Explanation / Answer

#include #include int walk(int distance); main() { int d,count; 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 "); printf(" How far would you like the robot to walk? "); scanf("%d",&d); if (d
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote