Skip to content

Commit

Permalink
Merge pull request #226 from chinmaykumbhare/master
Browse files Browse the repository at this point in the history
Fixed: Solution for Fibonacci Sequence using C(Issue #15)
  • Loading branch information
ephremdeme authored Oct 2, 2020
2 parents 382809c + 786fb03 commit a54a8da
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 a54a8da

Please sign in to comment.