We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b6e2ab5 commit 8b6bae9Copy full SHA for 8b6bae9
C++/Fibonacci.cpp
@@ -0,0 +1,25 @@
1
+#include <iostream>
2
+using namespace std;
3
+
4
+int main() {
5
+ int n, t1 = 0, t2 = 1, nextTerm = 0;
6
+ cout << "Enter the number of terms: ";
7
+ cin >> n;
8
+ cout << "Fibonacci Series: ";
9
+ for (int i = 1; i <= n; ++i) {
10
+ // Prints the first two terms.
11
+ if(i == 1) {
12
+ cout << t1 << ", ";
13
+ continue;
14
+ }
15
+ if(i == 2) {
16
+ cout << t2 << ", ";
17
18
19
+ nextTerm = t1 + t2;
20
+ t1 = t2;
21
+ t2 = nextTerm;
22
+ cout << nextTerm << ", ";
23
24
+ return 0;
25
+}
0 commit comments