Friday, February 10, 2017

Write a java program to generate Fibonacci Series to the N number. The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...


import java.util.Scanner;
import static java.lang.System.out;
class Fibonacci2
{
static public void main(String args[])
{
Scanner sc=new Scanner(System.in);
out.println("Enter a number to generate fibonacci series upto that no : ");
int n=sc.nextInt();
int a=0,b=1,fab=0;
while(fab<=n)
{
out.print(fab+"  ");
fab=a+b;
a=b;
b=fab;
}
    }
}

Share this

0 Comment to "Write a java program to generate Fibonacci Series to the N number. The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ..."

Post a Comment