Java program to generate fibonacci numbers

Java program to generate fibonacci numbers


class Fibonacci
{
public static void main(int n)
{
int a =0;int b=1;
System.out .print(a+" ");
System.out.print(b);
for(int i=1;i<=n-2;i++)
{
int c=a+b;
System.out.print(c+" ");
a=b;
b=c;
}
}
}

Output:-     10
                   0 1 1 2 3 5 8 13 21 34 

Java program to generate fibonacci numbers


No comments:

Powered by Blogger.