Topic 1387: Fibonacci sequence

Source: Internet
Author: User
Title Description:

We all know that the Fibonacci sequence now requires you to enter an integer n, and you output the nth of the Fibonacci sequence. The Fibonacci sequence is defined as follows:

Input:

The input may contain multiple test samples, for each test case,

The input includes an integer n (1<=n<=70). Output:

corresponding to each test case,

Outputs the value of the nth Xiang Feipo sequence. Sample Input:

3
Sample output:

2

Description The recursive time-out of the subject, you must first use an array to hold the Fibonacci sequence, and the array to use a long long type.

#include <stdio.h>
int main () {
int n,i;
Long Long f[71]={0,1};
for (i=2;i<=70;i++)//Remember is equal to 70

F[I]=F[I-1]+F[I-2];
while (scanf ("%d", &n)!=eof) {
printf ("%lld\n", F[n]);
}
return 0;
}//recursion will time out

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.