java progran on Fibonacci seeries
class Rfib
{
int fibo(int n)
{
int a=0,b=1,c=2,i;
if(n==1)
return(a);
else if(n==2)
return(b);
else
{
for(i=3;i<=n;i++)
{
c=a+b;
a=b;
b=c;
}
return(c);
}
}
}
class fib
{
public static void main(String args[])
{
int n,i,a=0,b=1,c;
Rfib f=new Rfib();
n=Integer.parseInt(args[0]);
for(i=1;i<=n;i++)
{
System.out.println(f.fibo(i));
}
for(i=1;i<n;i++)
{
if(i==1)
System.out.println(a);
else if(i==2)
System.out.println(b);
else
{
c=a+b;
a=b;
b=c;
System.out.println(c);
}
}
}
}
No comments:
Post a Comment