1091: Childhood life two or three things (multi-instance test) __zzuli-oj

Source: Internet
Author: User
Tags time limit
1091: The childhood life two or three things (multi-instance test)Time limit:1 Sec Memory limit:128 MB
submit:4334 solved:2473

Submit Status Web Board Description

Redraiment like to bounce when he was a child, and he likes to jump up and down the stairs.
But at a young age, he can only go one step at a time or jump on two.
There are now a total of N-step, please calculate the redraiment from the No. 0 order to the nth order altogether several walks. Input

Input includes multiple sets of data.
Each set of data includes one row: N (1≤n≤40).
Input ends with 0 Output

Each input includes one output.
The number of different walks for the redraiment to reach the nth order. Sample Input 130 Sample Output HINT

Source

***



#include <stdio.h>
#include <math.h>

int main ()
{
    int n,i,a,b,c;
    while (scanf ("%d", &n), n!=0)
    {
        a=1;b=2;
        if (n==1)
            printf ("1\n");
        else if (n==2)
            printf ("2\n");
        else
        {for
            (i=3; i<=n; i++)
            {
                c=a+b;
                a=b;
                b=c;
            }
            printf ("%d\n", c);
        }


    }
    return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.