mirror of
https://github.com/c0de-archive/hacktoberfest-2018.git
synced 2024-11-16 09:17:25 +00:00
6c5f934dbb
This code helps you to print the desired number of the Fibonacci number in a sequence.
16 lines
375 B
C++
16 lines
375 B
C++
#include <iostream>
|
|
using namespace std;
|
|
int main() {
|
|
int n1 = 0, n2 = 1, n3, num;
|
|
cout << "Enter the number of elements: ";
|
|
cin >> num;
|
|
cout << n1 << " " << n2 << " ";
|
|
for(int i = 2; i < num; ++i){
|
|
n3 = n1 + n2;
|
|
cout << n3 << " ";
|
|
n1 = n2;
|
|
n2 = n3;
|
|
}
|
|
return 0;
|
|
}
|