Find the nth number in the Fibonacci sequence

Source: Internet
Author: User

Title Description Description

To find the nth number in Fibonacci sequence by recursive method

input/output format input/output Input Format:
A row, a positive integer n
output Format:A line, a number, that represents the nth number in the Fibonacci sequence. input and Output sample sample Input/output sample Test point # # Input Sample:15 Sample output: 610 idea: After discussion, the recursive formula of Fibonacci sequence: F (n-1) +f (n-2), and then direct recursion is obtained. The code is as follows (here is a long long type, too small to kneel ...) ):
1#include <stdio.h>2 Long LongFunLong LongN)3 {4     if(n==0)return 0;5     Else if(n==1)return 1;6     Else return(Fun (n1) +fun (n2));7 }8 intMain ()9 {Ten     Long LongN; Onescanf"%d",&n); Aprintf"%i64d\n", Fun (n));  -     return 0; -}

Find the nth number in the Fibonacci sequence

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.