Skip to content

Commit

Permalink
Create fibo.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
harshgauttam authored Oct 30, 2018
1 parent a4f94c9 commit 2c238a5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions fibo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
using namespace std;

int main()
{
int n, t1 = 0, t2 = 1, nextTerm = 0;

cout << "Enter the number of terms: ";
cin >> n;

cout << "Fibonacci Series: ";

for (int i = 1; i <= n; ++i)
{
// Prints the first two terms.
if(i == 1)
{
cout << " " << t1;
continue;
}
if(i == 2)
{
cout << t2 << " ";
continue;
}
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;

cout << nextTerm << " ";
}
return 0;
}

0 comments on commit 2c238a5

Please sign in to comment.