description: This is C++ program to the fibonacci series to n number
code:
code:
/* C++ program to the fibonacci series */
#include <iostream>
using namespace std;
int main()
{
int number, x = 0, y = 1, temp = 0;
cout << "Enter the value to print fibonacci series :";
cin >> number;
cout << "Fibonacci Series of: "<<number;
for (int j = 1; j <= number; ++j)
{
// if number is 1 and 2 then print it
if(j == 1)
{
cout << " " << x;
continue;
}
if(j == 2)
{
cout << y << " ";
continue;
}
temp = x + y;
x = y;
y = temp;
cout << temp << " ";
}
return 0;
}
output:
Enter the number to print n :10
Fibonacci Series: 10 01 1 2 3 5 8 13 21 34