Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PROGRAM TO PRINT FIBONACCI NUMBERS
#1

Code:
import java.io.*;
class Fib
{
public static void main(String arg[])throws IOException
{
DataInputStream dim=new DataInputStream(System.in);
  System.out.println("Enter the limit");
  int n=Integer.parseInt(dim.readLine());
int f1=0,f2=1,f3=0;
  while(f3<=n)
{
  f1=f2;
  f2=f3;
  System.out.println(f3);
  f3=f1+f2;
}
}
}

OUTPUT

E:\ 5BCA-B\lijo\java >java Fib
Enter the limit
6
0
1
1
2
3
5
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.