C language: Using arrays to deal with the problem of solving Fibonacci series

Source: Internet
Author: User

An array is used to deal with the problem of solving Fibonacci sequence.

Solution: Program:

#include <stdio.h>

int main ()

{

int I, f[20] = {};//to the first two elements f[0] and f[1] assigns the initial value 1

for (i = 2; i <; i++)

{

F[i] = f[i-2]+f[i-1];//to find out the value of f[2]~f[19]

}

for (i = 0; i<20; i++)

{

if (i% 5 = = 0)//controls the line break after 5 numbers per output

{

printf ("\ n");

}

printf ("%d\t", F[i]);//Output a number

}

printf ("\ n");

return 0;

}

Results:

1 1 2) 3 5

8 13 21) 34 55

89 144 233) 377 610

987 1597 2584) 4181 6765

Please press any key to continue ...


This article is from the "Rock Owl" blog, please be sure to keep this source http://yaoyaolx.blog.51cto.com/10732111/1746391

C language: Using arrays to deal with the problem of solving Fibonacci series

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.