c program to print Fibonacci series
C Programming

C Program to Print Fibonacci Series

C Program to Print Fibonacci Series

The Fibonacci series is the sequence of numbers in which every number is the sum of the preceding two numbers in the sequence.

For example  0 1 1 2 3 5 8 13 21

C Program to Print the Fibonacci series is given below.

#include <stdio.h>

int main( )
{

int i, n;

// here we are going initialize first and second terms t1 and t2

int t1 = 0, t2 = 1;

// now initialize the next term (3rd term)

int nextTerm = t1 + t2;

//accept the no. of terms from user

printf(“Enter the number of terms: “);

scanf(“%d”, &n);

// now print the first two terms t1 and t2

printf(“Fibonacci Series: %d, %d, “, t1, t2);

// now print 3rd to nth terms

for (i = 3; i <= n; ++i)
{
printf(“%d, “, nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;

}

return 0;

}

Output

Enter the number of terms: 8

Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13,

Leave a Reply

Your email address will not be published. Required fields are marked *