jeudi 3 septembre 2020

What am i doing wrong here exactly?

i'm writing a program to identify if the entered number from the user is a Fibonacci number,program runs fine and it does what it needs to do,but i'm trying to make the program say that it isn't a Fibonacci number when the user enters a number that isn't one,its not working,and i'm not sure on what i need to adjust

Here's the code :

#include <stdio.h>

int main () {
   int number;
   int flag=0;
   int a=0;
   int b=1;
   int NextTerm;
   
   
   printf("this is a program to determine if a number is a Fibonacci number\n");
   printf("please enter your number\n");
   printf("the number you entered is : ");
   scanf("%d",&number);
   
   
   while (true){
    NextTerm=a+b;
    a=b;
       b=NextTerm;
       if(a==number){
       flag=1;
        break;
       }
      
      }
      
if(flag==1) {
    printf("The number you entered which is %d is a Fibonacci Number\n",number);
}     
else if (flag==0) {
    printf("The number you entered which is %d is not a Fibonacci Number\n",number);
} 

 
      
 
  return 0; 
}


Aucun commentaire:

Enregistrer un commentaire