Menu Close

Find the total number of ways to reach the tree house

Steve Waugh and Mark Waugh are sitting at the bottom of their tree house and debating in how many ways they can jump up the stairs on the tree and reach the tree house. 
Because Steve Waugh is older than Mark Waugh, he can jump one, two, or three stairs in one step while Mark Waugh can jump just one or two stairs in one step.

Input:
The number of stairs to be covered.

Output:
Print the Number of total ways to reach to the top for Steve Waugh in the first line and Number of total ways to reach at the top for Mark Waugh in the second line. 
#include <stdio.h>
int i;
int main()
{ int markwaugh,stevewaugh,n;
 //printf("Total number of stairs to be covered: ");
   scanf("%d",&n);
   int arr[n+1];
   arr[0] = 1;
   arr[1] = 1;
   arr[2] = 2;
   for (i = 3; i <=n; i++)
   arr[i] = arr[i - 1] + arr[i - 2]+ arr[i - 3];
   stevewaugh=arr[n];
   for(i=2;i<=n;i++)
   arr[i]=arr[i - 1] + arr[i - 2];
   markwaugh=arr[n];
   printf("Steve Waugh:%d\nMark Waugh:%d\n",stevewaugh,markwaugh);
   return 0;
}

INPUT_1:
Total number of stairs to be covered:  14

OUTPUT:
Steve Waugh: 3136
Mark Waugh: 610


INPUT_2:
Total number of stairs to be covered:  10

OUTPUT:
Steve Waugh: 274
Mark Waugh: 89


INPUT_3:
Total number of stairs to be covered:  20

OUTPUT:
Steve Waugh: 121415
Mark Waugh: 10946



INPUT_4:
Total number of stairs to be covered:  7

OUTPUT:
Steve Waugh: 44
Mark Waugh: 21


INPUT_5:
Total number of stairs to be covered:  3

OUTPUT:
Steve Waugh: 4
Mark Waugh: 3


ILLUSTRATION

EXECUTED USING GCC

Morae! Q