•○●Hey Guys●○•

Write a program in Java to enter a number and find out if the entered number is in fibonacci series or not.
Answers
Answered by
12
Answer:
Here comes the Java program for the question.
import java.util.*;
public class CheckFibonacciNumber {
public static void main(String args[]) {
int a=1,b=0,c=0,n;
boolean x=false;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number - ");
n=sc.nextInt();
while(c<=n) {
if(n==c) {
x=true;
break;
}
c=a+b;
a=b;
b=c;
}
if(x)
System.out.println("Number is a Fibonacci Number.");
else
System.out.println("Number is not a Fibonacci Number.");
sc.close();
}
}
Algorithm:
- START.
- Initialise x=false.
- Accept the number, say n.
- Calculate all the fibonacci numbers till n.
- Check if that Fibonacci number is equal to n or not. If true, x=true. Break the loop.
- Check if x is true. If true, number is a fibonacci number else not.
- Display the result.
See the attachment for output.
Attachments:



Similar questions
CBSE BOARD XII,
3 months ago
Social Sciences,
3 months ago
English,
3 months ago
Math,
6 months ago
Political Science,
1 year ago