INDEX

8.25.2012

Search number is Fibonacci or not

Q. Write a C program to check number whether a number is Fibonacci term or not.

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************/

Output of number is Fibonacci term C program
Screen shot for number is Fibonacci term C program


Output of number is not a Fibonacci term C program
Screen shot for number is not comes
in Fibonacci term C program

1 comment: