C Program to check fibonacci numbers
Simple C program to check Fibonacci numbers: Fibonacci series is 0,1,1,2,3,5,8,13,21.. So if number is in this series then program will print that number is in Fibonacci series otherwise number is not in Fibonacci series.
#include<stdio.h> int main() { int n1=0,n2=1,n,c=1; printf("Enter a number: "); scanf("%d",&n); if(n==0||n==1) { printf("Number is in fibonacci series\n"); } else while(n2<n) { int temp=n1; n1=n2; n2=temp+n2; if(n2==n) { c=1; } else { c=0; } } if(c==0) printf("Number is not in fibonacci series\n"); else printf("Number is in fibonacci series\n"); }