/*1.Fibonacci program using Recursive Functions*/
import java.lang.*;
import java.io.*;
class FibonacciRecursive
{
public static void main(String args[])throws IOException
{
int n;
BufferedReader d=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter The range");
n=Integer.parseInt(d.readLine());
System.out.println("The fibonacci series is:");
Fibonaccino(n);//funcion Calling
}//Main method End.
static void Fibonaccino(int n)
{
int i,sum=0,f=1,res;
for(i=0;i<n;i++)
{
res=sum+f;
System.out.println(sum);
sum=f;
f=res;
}
System.out.println("\nTask completed.");
}
}
Output:
E:\javamani>java FibonacciRecursive
Enter The range
10
The fibonacci series is:
0
1
1
2
3
5
8
13
21
34
Task completed.
0 comments:
Post a Comment