Home Uncategorized fibonacci number or not in C

# fibonacci number or not in C

SHARE

Here we written code for to check whether the given number is in belongs to Fibonacci series or not.

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

Task: Write a C program to print nth term in Fibonacci series.

## Write a C program to check the given integer is Fibonacci number or not.

#include<stdio.h>
void main()
{
int f,s,t,n,i,flg; //’f’ is 1st num,’s’ is 2nd num,’t’ for 3rd new generated num, ‘n’ is user defined, ‘i’ is for iteratons, “flg” is Flag variable.
printf(“Enter a number : “);
if(n<0)
{
return;
}
f=flg=t=0; //set f,flg and t variables set as zero for check conditions.
if(n==0)
flg=1; //set flg variable as ‘1’ for founding the integer in series.
else
{
s=1; //set ‘s’ variable as ‘1’ to generate next numbers of series.
while(t<n)
{
t=f+s; //Generating next number in the series by adding preceding two intigers.
if(n==t)
flg=1;
f=s;
s=t; //Shifting the last two terms of series to ‘f’ & ‘s’ for genarating next number in the series.
}
}
if(flg==1)
printf(“Given integer is a Fibanacci number.\n”);
else
printf(“Given integer is Not Fibanacci number.\n”);
return;
}

Output:
i) Enter a number : 610
Given integer is a Fibanacci number.

ii) Enter a number : 812
Given integer is Not Fibanacci number.

Back to the programs.