import java.io.*;
class Recursion
{
int a,b,c,limit;
BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
Recursion()
{
a=0;b=1;c=0;
}
void input()throws IOException
{
System.out.println("Enter the limit");
limit=Integer.parseInt(x.readLine());
}
int fib(int n)
{
if(n!=limit)
{
c=a+b;
b=a;
a=c;
return c;
}
else return fib(++n);
}
void generatefibseries()
{
System.out.println();
for(int i=1;i<=limit;i++)
System.out.println(fib(i)+" ");
}
public static void main (String[] args)throws IOException
{
Recursion call=new Recursion();
call.input();
call.generatefibseries();
}
}
class Recursion
{
int a,b,c,limit;
BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
Recursion()
{
a=0;b=1;c=0;
}
void input()throws IOException
{
System.out.println("Enter the limit");
limit=Integer.parseInt(x.readLine());
}
int fib(int n)
{
if(n!=limit)
{
c=a+b;
b=a;
a=c;
return c;
}
else return fib(++n);
}
void generatefibseries()
{
System.out.println();
for(int i=1;i<=limit;i++)
System.out.println(fib(i)+" ");
}
public static void main (String[] args)throws IOException
{
Recursion call=new Recursion();
call.input();
call.generatefibseries();
}
}
No comments:
Post a Comment