package com.alok;
import java.util.Scanner;
class calc
{
int fibo(int n)
{
if(n==0)
return 0;
if(n==1)
return 1;
else
return fibo(n-1)+fibo(n-2);
}
}
public class Fibonacci
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter fibonacci Term :");
int n=sc.nextInt();
System.out.println("Fibonacci Series is :\n");
calc c=new calc();
for(int i=0;i<n;i++)
{
System.out.print(" "+c.fibo(i));
}
}
}
O/P:-
Enter fibonacci Term :
8
Fibonacci Series is :
0 1 1 2 3 5 8 13
sir,
ReplyDeletehoe to print a febonacci series in reverse order like
8,5,3,2,1,1,0
write for(i=n;i>=0;i--)
ReplyDeletenow result will print in recerse order
Sir how to print reverse Fibonacci series without using recursion ??
DeleteThis comment has been removed by the author.
Deleteint a=0,b=1;
DeleteS.o.p (a,b);
for(i=0;i<n-2;i++)
{
sum=a+b;
S.o.p(sum);
a=b;
b=sum;
}
Sir how to print reverse Fibonacci series without using recursion ??
ReplyDeleteHi, this is good program as a learner. Try to implement using array to stored computed value, instead of vast number of recursive calls. Test your program to print count of 30, 50 or more numbers.
ReplyDelete