//Display Fibonacci series up to given limit
import java.util.Scanner;
public class Fibonacci {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int l;
System.out.println("Enter a limit for fibonacci series:");
l=sc.nextInt();
if(l<=0)
System.out.println("Invalid input");
else
{
int a=0,b=1,c;
System.out.println("Fibonacci Series for limit "+l);
System.out.println(a);
System.out.println(b);
while(l>0)
{
c=a+b;
System.out.println(c);
a=b;
b=c;
l--;
}
}
}
}
import java.util.Scanner;
public class Fibonacci {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int l;
System.out.println("Enter a limit for fibonacci series:");
l=sc.nextInt();
if(l<=0)
System.out.println("Invalid input");
else
{
int a=0,b=1,c;
System.out.println("Fibonacci Series for limit "+l);
System.out.println(a);
System.out.println(b);
while(l>0)
{
c=a+b;
System.out.println(c);
a=b;
b=c;
l--;
}
}
}
}
No comments:
Post a Comment