import
java.util.Scanner;
class fibonacci
{
public static void main(String args[]) {
int i,n,a=0,b=1,c;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of
fibonacci terms: ");
n=sc.nextInt();
System.out.println("0\n1");
for(i=0;i<n-2;i++) {
c=a+b;
System.out.println(c);
a=b;
b=c;
}
}
}
OUTPUT:
C:\jdk1.7.0\bin>java
fibonacci
Enter the
number of fibonacci terms: 10
0
1
1
2
3
5
8
13
21
34
No comments:
Post a Comment