From 786fb030b03965a1e607db86adb550afdac93195 Mon Sep 17 00:00:00 2001 From: chinmaykumbhare Date: Fri, 2 Oct 2020 23:13:24 +0530 Subject: [PATCH] Fixed: Solution for Fibonacci Sequence using C(Issue #15) As suggested by the Author, Fixed the solution for issue #15 in the github repo --- Mathematics/fibonacci/FibonacciSequence.c | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Mathematics/fibonacci/FibonacciSequence.c diff --git a/Mathematics/fibonacci/FibonacciSequence.c b/Mathematics/fibonacci/FibonacciSequence.c new file mode 100644 index 00000000..f1624568 --- /dev/null +++ b/Mathematics/fibonacci/FibonacciSequence.c @@ -0,0 +1,40 @@ + + +/** + * GitHub username: chinmaykumbhare + * + * Issue Statement: + * Implement Fibonacci sequence in any language. Recursive is appreciated. + */ + +#include + +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"); + +}