Nyist 13 Fibonacci count

Source: Internet
Author: User
Fibonacci time limit: 3000 MS | memory limit: 65535 kb difficulty: 1
Description
The infinite series, 21, 34, 55... is called the Fibonacci series, which can be recursively defined
F (n) = 1 ...... (n = 1 or N = 2)
F (n) = f (n-1) + f (n-2)... (n> 2)
I want you to calculate the nth Number of fepona. (1st and the second are both 1)
 
Input
The first row is an integer m (M <5), indicating a total of M groups of test data.
Each test data has only one row and only one integer n (n <20)
Output
Input n to each group, and output the nth Number of ononacci
Sample Input
3135
Sample output
125





 

 

 

 

# Include <stdio. h>
Int main ()
{
Int A [10000], M, N, I;
A [0] = 1;
A [1] = 1;
Scanf ("% d", & M );
While (M --)
{
Scanf ("% d", & N );
For (I = 2; I <n; I ++)
{
A [I] = A [I-1] + A [I-2];
}
Printf ("% d \ n", a [n-1]);
}
Return 0;
}

 


************************************

 

 

# Include <stdio. h>
Int main ()
{Int m, n, I;
Int A [20] = {1, 1, 2, 3 };
Scanf ("% d", & M );
While (M --)
{
Scanf ("% d", & N );
For (I = 2; I <n; I ++) // for (I = 2; I <= N; I ++)
{
A [I] = A [I-1] + A [I-2];
}
Printf ("% d \ n", a [n-1]);
}

}


**************************************** **

 

# Include <iostream>
Using namespace STD;
Int main ()
{
Int I, a [20], M, T;
A [1] = 1; A [2] = 1;
For (I = 3; I <= 20; I ++) A [I] = A [I-2] + A [I-1]; // calculate the first 20

Cin> m;
While (M --)
{
Cin> T;
Cout <A [T] <Endl;
}
// While (1 );
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.