Write a C program to Display Fibonacci Series Up to n Terms.
Function Main
Declare Integer i
Declare Integer n
Declare Integer t1
Declare Integer t2
Assign t1 = 0
Assign t2 = 1
Declare Integer nextTerm
Assign nextTerm = t1 + t2
Output "Enter the number of terms: "
Input n
Output "Fibonacci Series: " &t1
Output ", " &t2
For i = 3 to n
Output ", " &nextTerm
Assign t1 = t2
Assign t2 = nextTerm
Assign nextTerm = t1 + t2
End
End
#include <stdio.h>
int main() {
int i, n;
int t1 = 0, t2 = 1;
int nextTerm = t1 + t2;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: %d, %d, ", t1, t2);
for (i = 3; i <= n; ++i) {
printf("%d, ", nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
return 0;
}
Enter the number of terms: 10
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
Published by Md. Anisur Rahman
I am Md. Anisur Rahman. I have completed Cyber Security for MSCSE at United International University in 2022.I have completed PGDIT from IIT, Jahangirnagar University in 2020. I'm a Head of IT at Programming24 School.
View all posts by Md. Anisur Rahman