[100 questions] 19th questions (fepona wedge Series)

Source: Internet
Author: User

I. Question:Input N in the fastest wayFibonacciN of the number of columns.

Ii. Definition: the series of Fibonacci are as follows:

0 n = 0
F (n) = 1 n = 1, 2
F (n-1) + f (n-2) n> 2

// 0 1 1 2 3 5 8 13 21 34 55 144 233 377 610 9871597 ..........
Iii. Analysis:
Note: When you calculate 100th or even greater items, make sure that you use what type, long integer type? Orlong long int storage.
Otherwise, no results will be obtained from the computer. Therefore, the selected data type is critical.

4. Source Code:

# include <iostream> <br/> using namespace std; </P> <p> long Fibonacci (int n) <br/> {<br/> If (n> = 0) <br/>{</P> <p> If (0 = N) <br/> return 0; <br/> else if (1 = n | 2 = N) <br/> return 1; <br/> else <br/> return maid (n-1) + maid (n-2); <br/>}</P> <p> int main () <br/> {<br/> for (INT I = 0; I <10; I ++) <br/> cout <Fibonacci (I) <Endl; </P> <p> return 0; <br/>}

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.