import java.util.*;
class Fibonacci
{
public static void main()
{
int a = -1, b = 1;
Scanner s=new Scanner(System.in);
System.out.println("Enter the value for n: ");
int n=s.nextInt();
int c;
for(int x = 1; x <= n; x++)
{
c = a + b;
System.out.println(c);
a = b;
b = c;
}
}
}
class Fibonacci
{
public static void main()
{
int a = -1, b = 1;
Scanner s=new Scanner(System.in);
System.out.println("Enter the value for n: ");
int n=s.nextInt();
int c;
for(int x = 1; x <= n; x++)
{
c = a + b;
System.out.println(c);
a = b;
b = c;
}
}
}
No comments:
Post a Comment
Please write your comment in the box below...