• We just launched and are currently in beta. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

Fibonacci Series in C

Future

Low Latency Developer
F Rep
0
0
0
Rep
0
F Vouches
0
0
0
Vouches
0
Posts
123
Likes
186
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
A simple implementation of the Fibonacci number series. The Fibonacci series is formed by adding the latest two numbers to get the next one, starting from 0 and 1: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...

  1. #include<stdio.h> /* C Standard Input and Output Library*/

  2. /*Variable declarations*/
  3. int

    number_of_terms;
  4. int

    pre_term =

    0

    ;
  5. int

    post_term =

    1

    ;
  6. int

    next_transition;
  7. int

    loop_counter;


  8. int

    main(

    void

    )

    /* The main method*/
  9. {
  10. /* Brief detail on the screen about the program*/
  11. printf

    (

    " /*************************************************************************\n

    * Mureithi David Wachira *\n

    * P15/2204/2011 *\n

    * *\n

    * University of Nairobi *\n

    * School of Computing & Informatics *\n

    * *\n

    * Course: DATA STRUCTURES AND ALGORITHMS (CSC 211) *\n

    * Date: Thursday 19th September 2013 *\n

    * *\n

    * A program to print the fibonacci number *\n

    * series *\n

    * *\n

    *************************************************************************/\n

    "

    )

    ;

  12. printf

    (

    "\n

    Please enter the number of terms\n

    "

    )

    ;

    /* Prompt to instruct user to enter an integer*/
  13. scanf

    (

    "%d"

    ,&

    number_of_terms)

    ;

    /* Capture of the integer by the system using function scanf()*/

  14. printf

    (

    "\n

    \n

    "

    )

    ;

    /* Skipping two lines*/

  15. for

    (

    loop_counter =

    0

    ;

    loop_counter <

    number_of_terms ;

    loop_counter++

    )
  16. {
  17. if

    (

    loop_counter <=

    1

    )
  18. next_transition =

    loop_counter;

  19. else
  20. {
  21. next_transition =

    pre_term +

    post_term;
  22. pre_term =

    post_term;
  23. post_term =

    next_transition;
  24. }
  25. printf

    (

    "%d\t

    "

    ,

    next_transition)

    ;
  26. }
  27. printf

    (

    "\n

    \n

    "

    )

    ;

    /* Skipping two lines*/

  28. return

    0

    ;

    /* An indication that the program runs successfully*/
  29. }

    /* The end of the main method*/

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,497

347,672

347,680

Top