I have written this program to detect whether two numbers are consecutive terms of the fibonacci series. The code that I have written below gives me wrong answer when I enter 21 and 34 and 55 and 89 (gives right answer for other entries). Below is the fibonacci series representation:
1 1 2 3 5 8 13 21 34 55 89...
A fibonacci series is made up of consecutively adding two previous terms. Below is my code;
Thank you for your help.Code:#include<stdio.h> int main() { int d,e,a,b,i; printf("enter the numbers >1 to be checked"); scanf("%d%d",&d,&e); while(a!=1 && (b!=1||0)) { a=e-d; b=d-a; e=a; d=b; } if(a==1 && (b==1||0)) { printf("the given numbers were fibonacci series numbers"); } else { printf("the given numbers were not fibonacci numbers"); } system("pause"); return 0; }



1Likes
LinkBack URL
About LinkBacks



