Answer to Question #302064 in C for Pratigyan

Question #302064

2. The distance from Point A to Point B is n meters(n>2). A person goes from point A to point B walking by taking steps of size 2 meters or 3 meters. Please write a program to find the total number of ways in which the person can do this. The program should take n as input. For e.g., if input n = 5 the output should be 2, since the person can do this in two ways:



1. Take 2 steps followed by 3 steps.



2. Take 3 steps followed by 2 steps.

1
Expert's answer
2022-02-24T12:19:06-0500
#include <stdio.h>

int main() {
  int n;
  printf("%d", &n);
  int steps[n];
  steps[0] = steps[1] = 0;
  steps[2] = 1;
  for (int i = 3; i < n; i++) {
    steps[i] = stets[i-2] + steps[i-3] + 2;
  }
  printf("%d\n", steps[n-1]);
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS