Created
August 1, 2016 09:48
-
-
Save stinkymonkeyph/ca00549e8faf30987156f613e23a77e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Author: Nelmin Jay Magan Anoc | |
* | |
*/ | |
#include<stdio.h> | |
void printFibonnaciSequence(int); | |
int setNumberOfTerms(); | |
int main(){ | |
/*we simply call a setter function to set number of terms | |
*and pass the return value to print fibonacci sequence | |
*/ | |
printFibonnaciSequence(setNumberOfTerms()); | |
return 0; | |
} | |
int setNumberOfTerms(){ | |
int numberOfTerms = 0; | |
printf("Enter the number of terms: "); | |
scanf("%d",&numberOfTerms); | |
return numberOfTerms; | |
} | |
void printFibonnaciSequence(int numberOfTerms){ | |
int term1 = 0 ; | |
int term2 = 1 ; | |
int nextTerm = 0; | |
int incrementControl ; | |
/*we know that first two terms of fibo sequence is 0 and 1 so we print | |
*it directly | |
*/ | |
printf("Fibonacci Sequence: %d, %d, ",term1,term2); | |
for(incrementControl=3; incrementControl <= numberOfTerms ; ++incrementControl){ | |
nextTerm = term1 + term2 ; | |
term1 = term2; | |
term2 = nextTerm; | |
printf("%d, ",nextTerm); | |
} | |
/*the computation is always the sum of two consecutive integers | |
*next we swap these terms | |
*and print the result | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment