Science, asked by bindusai357, 6 months ago

Michael has a beautiful house. There is only one
staircase to reach his bedroom. He used to
climb either 1 stair or 2 stairs at a time. If we
consider all possible combinations of climbing,
in how many ways can Michael reach to the top?
Input Format
An Integer P denotes the number of stairs in the
staircase
If the number of stairs beyond 20, the output
should print "Wrong Infrastructure".
Output Format
The number of ways Michael can climb the
staircase to reach to the top.
Constraints
1=P.C=20
Sample1
input
5
Output​ 8

Answers

Answered by mdwasimakram2195
0

Answer:

#include<stdio.h>

#include<stdlib.h>

int main()

{

   int N, i;

   scanf("%d", &N);

   if(N>20)

   {

       printf("Wrong Infrastructure");

   }

   else

   {

   int steps[N+1];

   steps[0] = 1;

   steps[1] = 1;

   steps[2] = 2;

   for (i = 2; i<=N; i++)

   {

       steps[i] = steps[i-1] + steps[i-2];

   }

   printf("%d", steps[N]);

   }

   return 0;

}

Explanation:

Similar questions