Home Uncategorized Fibonacci series in C language

Fibonacci series in C language

SHARE

Here we written code for print Fibonacci series with output.

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

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

#include<stdio.h>
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 iteratons.

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

if(n<=0)
{
return;
}
f=0;
printf(“The FIBONACCI Series is :\n%d”,f);
if(n>1)
{
s=1;
printf(“\t%d”,s);
}
else
return;
for(i=2;i<n;i++)
{
t=f+s;//By adding of preceding numbers next numbers will generate in Fibonacci series.

printf(“\t%d”,t);
f=s;
s=t;//Shifting the last two terms of series to ‘f’ & ‘s’ for generating next number in the series.
}
return;
}

Output:
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