/* Fibonacci series Program in Java */
/*1.Fibonacci program using Non-Recursive Functions*/
import java.lang.*;
import java.io.*;
class Fibonacci
{
public static void main(String args[])throws IOException
{
int i,sum=0,f=1,res,n;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Hey boss This is Fibonacci series Generator program");
System.out.println("Enter The range");
n=Integer.parseInt(br.readLine());
System.out.println("The fibonacci series is:");
for(i=0;i<n;i++)
{
res=sum+f;
System.out.println(sum);
sum=f;
f=res;
}
System.out.println("\nTask completed.");
}
}
Output:
Hey boss This is Fibonacci series Generator program
Enter The range
20
The fibonacci series is:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
Task completed.
0 comments:
Post a Comment