import java.io.*;
class Fibonacci
{
public static void main(String args[])
{
BufferedReader bf=new BufferedReader( new InputStreamReader(System.in));
int a=0,b=1,c=0,i,m=0;
try
{
System.out.println("Enter the number upto which fibonacci series is displayed");
m=Integer.parseInt(bf.readLine());
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println(a);
for(i=1;a+b<=m;++i)
{
c=a+b;
System.out.println(" "+c);
a=b;
b=c;
}
}
}
class Fibonacci
{
public static void main(String args[])
{
BufferedReader bf=new BufferedReader( new InputStreamReader(System.in));
int a=0,b=1,c=0,i,m=0;
try
{
System.out.println("Enter the number upto which fibonacci series is displayed");
m=Integer.parseInt(bf.readLine());
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println(a);
for(i=1;a+b<=m;++i)
{
c=a+b;
System.out.println(" "+c);
a=b;
b=c;
}
}
}
Ty
ReplyDelete