Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions Fibonacci.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
class FibonacciSeries {
public static void main(String args[])
{
int n1=0,n2=1,n3,i,count=10;

//printing 0 and 1
System.out.print(n1+" "+n2);

//loop starts from 2 because 0 and 1 are already printed
for(i=2;i<count;++i) {
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
public static void main(String args[])
{
int n1=0,n2=1,n3,i,count;
Scanner scanner=new Scanner(System.in);
System.out.print("Enter a count : ");
count=scanner.nextInt();


//printing 0 and 1
if(count<2){
System.out.print(n1+" "+n2);
}


//loop starts from 2 because 0 and 1 are already printed
for(i=2;i<=count;++i) {
System.out.print(n1+" "+n2);
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
}
}
}
}