Skip to content

Commit

Permalink
Fixed: Solution for Fibonacci Sequence using C(Issue #15)
Browse files Browse the repository at this point in the history
As suggested by the Author, Fixed the solution for issue #15 in the github repo
  • Loading branch information
chinmaykumbhare committed Oct 2, 2020
1 parent ac9e851 commit 786fb03
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Mathematics/fibonacci/FibonacciSequence.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@


/**
* GitHub username: chinmaykumbhare
*
* Issue Statement:
* Implement Fibonacci sequence in any language. Recursive is appreciated.
*/

#include <stdio.h>

void main (void) {

int num = 0;

//enter the number of elements you would like to display as output

scanf(" %d", &num);

//using 3 variables, namely, prev for previous term. current for current term and next for next term in the sequence

int prev = 0, current = 1, next = 1;

//loop for calculating and printing the next number in fibonacci series

for(int loop = 0; loop < num; loop++) {

printf("%d ", prev);

next = current + prev;

prev = current;

current = next;

}

printf("\n");

}

0 comments on commit 786fb03

Please sign in to comment.