Write a program which checks a 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 iterations, “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 integers.
s=t; //Shifting the last two terms of series to ‘f’ & ‘s’ for generating next number in the series.
printf(“Given integer is a Fibonacci number.\n”);
printf(“Given integer is Not Fibonacci number.\n”);
i) Enter a number : 610
Given integer is a Fibonacci number.
ii) Enter a number : 812
Given integer is Not Fibonacci number.
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, and photo). We will display your details in our site.
Task: Write a C program to print nth term in Fibonacci series.