There is someone to climb 39 steps. Each step can only take 1 or 2 steps. Take the left foot first, then alternate left and right, and the last step is to take the right foot, that is to say, take an even number of steps. Write a recursive function to output how many different ways are there to go up the 39 steps? You must briefly explain the basic idea of program realization in the “Lab Report”.
#include<stdio.h>
long int long_way_home(int a,int n)
{
if (a == 0 && n % 2 == 0)return 1;
else if (a < 0)return 0;
return long_way_home(a - 1, n + 1) + long_way_home(a - 2, n + 1);
}
int main()
{
int b = 39,c=0;
printf("there are %ld ways to go home", long_way_home(b, c));