Home C Language Basic C Programs Fibonacci series in C

Fibonacci series in C

Write a C Program to generate the first n terms of the Fibonacci series.


void main()


   int f,s,t,n,i; //’f’ is 1st num,’s’ is 2nd num,’t’ for 3rd new generated num, ‘n’ is no.of terms, ‘i’ is for iterations.

   printf(“Enter a value : “);

   scanf(“%d”,&n); // Read the number terms to print from the series.



      printf(“Please enter a valid number\n”);




   printf(“The FIBONACCI Series is :\n%d”,f);










      t=f+s;//By adding of preceding numbers next numbers will generate in Fibonacci series.



      s=t;//Shifting the last two terms of series to ‘f’ & ‘s’ for generating next number in the series.





i) Enter a value : 16

The FIBONACCI Series is :

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610

ii) Enter a value : 0

Please enter a valid number

For improvement of your coding skills we give some tasks along this. If you solve this tasks and send to our email (onlineexamshubteam@gmail.com) with your details. We will display your details(like Name, City, college, photo) in our site.

Task: Write a C program to generate the given range of terms of Fibonacci series.

For example user entered 7 & 10 then output will be: 8 13 21 34