Fibonacci Series in C

Language
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.  
  3.  /*Variable declarations*/
  4.  int number_of_terms;
  5.  int pre_term = 0;
  6.  int post_term = 1;
  7.  int next_transition;
  8.  int loop_counter;
  9.  
  10.  
  11. int main(void)/* The main method*/
  12. {
  13.     /* Brief detail on the screen about the program*/
  14.     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");
  15.  
  16.    printf("\nPlease enter the number of terms\n");/* Prompt to instruct user to enter an integer*/
  17.    scanf("%d",&number_of_terms);/* Capture of the integer by the system using function scanf()*/
  18.  
  19.    printf("\n\n");/* Skipping two lines*/
  20.  
  21.    for ( loop_counter = 0 ; loop_counter < number_of_terms ; loop_counter++ )
  22.    {
  23.       if ( loop_counter <= 1 )
  24.          next_transition = loop_counter;
  25.  
  26.       else
  27.       {
  28.          next_transition = pre_term + post_term;
  29.          pre_term = post_term;
  30.          post_term = next_transition;
  31.       }
  32.       printf("%d\t",next_transition);
  33.    }
  34.       printf("\n\n");/* Skipping two lines*/
  35.  
  36.    return 0;   /* An indication that the program runs successfully*/
  37. }              /* 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.

Add new comment