import java.util.*;
class Fibbonacci
{
public static void main(String args[])
{
int i,n;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
n=sc.nextInt();
System.out.println("fibonacci series\n");
for(i=1;i<=n-1;i++)
{
System.out.println(fibo(0,1,i));
}
}
static int fibo (int a,int b,int i)
{
if(i==1)
return b;
else
return (fibo(b,(a+b),(i-1)));
}
}
class Fibbonacci
{
public static void main(String args[])
{
int i,n;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
n=sc.nextInt();
System.out.println("fibonacci series\n");
for(i=1;i<=n-1;i++)
{
System.out.println(fibo(0,1,i));
}
}
static int fibo (int a,int b,int i)
{
if(i==1)
return b;
else
return (fibo(b,(a+b),(i-1)));
}
}
No comments :
Post a Comment