The Fibonacci series is a series of numbers in which each number is the sum of the two preceding numbers. The first two numbers of the Fibonacci sequence are 0 and 1, and the rest of the sequence is generated by adding the two previous numbers. In this program, we will print the Fibonacci series up to a certain number of terms using the C programming language.
Here's the code:
#include int main() { int n, first = 0, second = 1, next, c; printf("Enter the number of terms\n"); scanf("%d", &n); printf("First %d terms of Fibonacci series are:\n", n); for (c = 0; c < n; c++) { if (c <= 1) next = c; else { next = first + second; first = second; second = next; } printf("%d\n", next); } return 0; }
In this program, the user is asked to enter the number of terms they want to print in the Fibonacci series. The for
loop is used to generate the next number in the series by adding the previous two numbers. The if
statement is used to initialize the first two terms of the series to 0 and 1. Finally, the printf
statement is used to print the generated terms.
This program uses a basic approach to print the Fibonacci series, and it can be easily modified to meet the specific requirements of the user.