From 7796c9f1fa0b8ae99a45dd0624992b273dc28b90 Mon Sep 17 00:00:00 2001 From: subhadeepo4 <116870553+subhadeepo4@users.noreply.github.com> Date: Fri, 28 Oct 2022 13:23:19 +0530 Subject: [PATCH] Create fibo.c --- fibo.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 fibo.c diff --git a/fibo.c b/fibo.c new file mode 100644 index 0000000..a41e7e3 --- /dev/null +++ b/fibo.c @@ -0,0 +1,28 @@ +#include +int main() { + + int i, n; + + // initialize first and second terms + int t1 = 0, t2 = 1; + + // initialize the next term (3rd term) + int nextTerm = t1 + t2; + + // get no. of terms from user + printf("Enter the number of terms: "); + scanf("%d", &n); + + // print the first two terms t1 and t2 + printf("Fibonacci Series: %d, %d, ", t1, t2); + + // print 3rd to nth terms + for (i = 3; i <= n; ++i) { + printf("%d, ", nextTerm); + t1 = t2; + t2 = nextTerm; + nextTerm = t1 + t2; + } + + return 0; +}