Pages

Tuesday, July 3, 2012

fibonacci program in java

The numbers in the following sequence are called the fibonacci numbers .

0 , 1 , 1 , 2, 3 , 5 , 8 , 13 , …………..





class fibonacci{

public static void main(String args[])

{

int n=Integer.parseInt(args[0]);

int f=0,s=1;

int cur;

System.out.print(f+" "+s+" ");

do{

cur=f+s;

f=s;

s=cur;

System.out.print(cur+" ");

}while(cur




}

}

No comments:

Post a Comment