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 (email@example.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.
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 : “);
scanf(“%d”,&n); //Read the number.
printf(“Please enter a valid number\n”);
f=flg=t=0; //set f,flg and t variables set as zero for check conditions.
flg=1; //set flg variable as ‘1’ for founding the integer in series.
s=1; //set ‘s’ variable as ‘1’ to generate next numbers of series.
t=f+s; //Generating next number in the series by adding preceding two intigers.
s=t; //Shifting the last two terms of series to ‘f’ & ‘s’ for genarating next number in the series.
printf(“Given integer is a Fibanacci number.\n”);
printf(“Given integer is Not Fibanacci number.\n”);
i) Enter a number : 610
Given integer is a Fibanacci number.
ii) Enter a number : 812
Given integer is Not Fibanacci number.