hacktoberfest-2018/code/prvkrFibonacci.cpp
Prabhakar Deep 6c5f934dbb Created Fibonacci Series
This code helps you to print the desired number of the Fibonacci number in a sequence.
2018-10-08 10:09:05 -07:00

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;
}