Skip to content

Commit 46937dc

Browse files
authored
Merge pull request ephremdeme#197 from himanshi2608/master
added files to mathematics folder in cpp
2 parents 792537f + 44df6df commit 46937dc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int t1 = 0, t2 = 1, nextTerm = 0, n;
7+
8+
cout << "Enter a positive number: ";
9+
cin >> n;
10+
11+
// displays the first two terms which is always 0 and 1
12+
cout << "Fibonacci Series: " << t1 << ", " << t2 << ", ";
13+
14+
nextTerm = t1 + t2;
15+
16+
while(nextTerm <= n)
17+
{
18+
cout << nextTerm << ", ";
19+
t1 = t2;
20+
t2 = nextTerm;
21+
nextTerm = t1 + t2;
22+
}
23+
return 0;
24+
}

0 commit comments

Comments
 (0)