当前位置:网站首页>1091: two or three things in childhood (multi instance test)

1091: two or three things in childhood (multi instance test)

2022-07-06 07:06:00 Huaze flowers

Title Description

Redraiment When I was a child, I liked to walk and jump , He likes to jump up and down the stairs best . 
But when he was young, he could only go up one step at a time or jump up two steps at once . 
Now there is N Steps , Please calculate Redraiment From 0 Step to N There are several ways to walk the steps .

Input

Input includes multiple sets of data . 
Each set of data includes a row :N(1≤N≤40). 
Enter to 0 end

Output

Each input includes an output . 
by redraiment Arrive at n The number of different steps .

The sample input

1
3
0

Sample output

1
3
// Take one step , Jump two steps , from 0 Go to the N rank , Several walking methods 
// Enter multiple groups N, With 0 end 
// Output several ways 
// Input :
//1
//3
//0
// Output :
//1
//3


#include <stdio.h>
int main()
{
    int n,a[100],b,i;
    a[0]=1;
    a[1]=2;
    while(scanf("%d",&n))
        {
            if(n==0)
                break;
    if(n==1)
        printf("1\n");
        else if(n==2)
            printf("2\n");
    else if(n>2)
    {
        for(i=2;i<=n;i++)
        {
            a[i]=a[i-1]+a[i-2];
        }
    printf("%d\n",a[n-1]);
    }
        }
    return 0;
}

Running results :

Submit :

 

According to the title , You can find it by listing a few numbers , Fibonacci series can be used to calculate

Simply list a few examples of using Fibonacci sequence :

1. The bifurcation of trees

2. Number of petals

3. Rabbit breeding

4.1,2 Go up the steps

原网站

版权声明
本文为[Huaze flowers]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131946571041.html