import java.io.*;
public class Fibonacci
{
public static void main(String[] args) throws IOException
{
DataInputStream in=new DataInputStream(System.in);
System.out.println("\nENTER THE NUMBER OF TERMS TO BE GENERATED : ");
int n = Integer.parseInt(in.readLine());
System.out.println("\nFIBONACCI SERIES UPTO "+ n + " TERMS ");
for (int i = 1; i <= n; i++)
{
int f = fibo(i);
System.out.print(f +" ");
}
System.out.println("\n");
}
//to find nth Fibonacci number
public static int fibo(int n)
{
if (n <= 2)
return 1;
else
return fibo(n - 1) + fibo(n - 2);
}
}
public class Fibonacci
{
public static void main(String[] args) throws IOException
{
DataInputStream in=new DataInputStream(System.in);
System.out.println("\nENTER THE NUMBER OF TERMS TO BE GENERATED : ");
int n = Integer.parseInt(in.readLine());
System.out.println("\nFIBONACCI SERIES UPTO "+ n + " TERMS ");
for (int i = 1; i <= n; i++)
{
int f = fibo(i);
System.out.print(f +" ");
}
System.out.println("\n");
}
//to find nth Fibonacci number
public static int fibo(int n)
{
if (n <= 2)
return 1;
else
return fibo(n - 1) + fibo(n - 2);
}
}