Skip to content

Commit dceab34

Browse files
struong9tstreamDOTh
authored andcommitted
Fix #361: Add Fibonacci for C++ (#362)
* Fix #361: Add Fibonacci for C++ * Made into Function
1 parent 7a79ac1 commit dceab34

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Maths/Fibonacci/C++/Fibonacci.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
void fibonacci(int number)
6+
{
7+
int first = 0, second = 1, next;
8+
9+
for (int i = 0; i < number; i++)
10+
{
11+
cout << "\n" << first;
12+
next = first + second;
13+
first = second;
14+
second = next;
15+
}
16+
}
17+
18+
int main()
19+
{
20+
int number;
21+
22+
cout << "Enter number of terms for Series: ";
23+
cin >> number;
24+
25+
cout << "Fibonacci Series are: \n";
26+
fibonacci(number);
27+
}

0 commit comments

Comments
 (0)