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;
}