Fibonacci Series Generator
Learn how to generate the Fibonacci series in C using this attractive program.
#include <stdio.h>
int main() {
int n, first = 0, second = 1, next;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (int i = 0; i < n; i++) {
if (i <= 1) {
next = i;
} else {
next = first + second;
first = second;
second = next;
}
printf("%d ", next);
}
return 0;
}
Explanation
-
Step 1:
The program starts by including the standard input/output library
stdio.h. -
Step 2:
In the
main()function, integer variablesn,first,second, andnextare declared. - Step 3: The program prompts the user to enter the number of terms in the Fibonacci series.
-
Step 4:
The program generates and prints the Fibonacci series using a
forloop. -
Step 5:
The
nextterm is calculated by adding thefirstandsecondterms. The values offirstandsecondare updated accordingly.

If you have any doubts, Please let me know