Computer Science, asked by edusayanghosh1234, 5 months ago

Input a number and check it is in Fibonacci series or not.

Input=8

Output=in Fibonacci series

Input=9

Output=not in fibonacci series​

Answers

Answered by anindyaadhikari13
3

Question:-

  • Write a java program to input a number and check if it is a fibonacci number or not.

Program:-

import java.util.*;

class x

{

public static void main(String s[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter a number: ");

int x=sc.nextInt();

boolean x=false;

int a=0,b=1, c;

for(int i=1;i<=n;i++)

{

c=a+b;

a=b;

b=c;

if(x==c)

{

x=true;

break;

}

}

if(x)

System.out.println("Number is a fibonacci number.");

else

System.out.println("Number is not a fibonacci number.");

}

}

Similar questions