forked from Asiatik/codezilla
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix Asiatik#361: Add Fibonacci for C++ * Made into Function
- Loading branch information
1 parent
7a79ac1
commit dceab34
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
void fibonacci(int number) | ||
{ | ||
int first = 0, second = 1, next; | ||
|
||
for (int i = 0; i < number; i++) | ||
{ | ||
cout << "\n" << first; | ||
next = first + second; | ||
first = second; | ||
second = next; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int number; | ||
|
||
cout << "Enter number of terms for Series: "; | ||
cin >> number; | ||
|
||
cout << "Fibonacci Series are: \n"; | ||
fibonacci(number); | ||
} |