Fibonacci Series in C
Submitted by davidwachira on Friday, September 20, 2013 - 03:08.
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, ...
- #include<stdio.h> /* C Standard Input and Output Library*/
- /*Variable declarations*/
- int number_of_terms;
- int pre_term = 0;
- int post_term = 1;
- int next_transition;
- int loop_counter;
- int main(void)/* The main method*/
- {
- /* Brief detail on the screen about the program*/
- 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");
- for ( loop_counter = 0 ; loop_counter < number_of_terms ; loop_counter++ )
- {
- if ( loop_counter <= 1 )
- next_transition = loop_counter;
- else
- {
- next_transition = pre_term + post_term;
- pre_term = post_term;
- post_term = next_transition;
- }
- }
- return 0; /* An indication that the program runs successfully*/
- } /* 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
- 54 views