Q. Write a C program to check number whether a number is Fibonacci term or not.
Ans.
Ans.
/*c program to check a number is include in Fibonacci term or not*/
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c,next,num;
printf("Enter any number: ");
scanf("%d", &num);
if((num==0)||(num==1))
printf("\n%d is a Fibonacci term",num);
else
{
a=0;
b=1;
c=a+b;
while(c<num)
{
a=b;
b=c;
c=a+b;
}
if(c==num)
printf("\n%d is a Fibonacci term",num);
else
printf("\n%d is not a Fibonacci term",num);
}
getch();
return 0;
}
/************Output************/
Screen shot for number is Fibonacci term C program |
Screen shot for number is not comes in Fibonacci term C program |
Comments
Post a Comment