CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
//fibonacci series
int main() {
int a=0,b=1,c,n;
// cout<<" Enter no. of terms -> ";
cin>>n;
//a & b act as first two terms of series
cout<<"\n Fibonacci Series -> "<<a<<" "<<b<<" ";
for(int i=2;i<n;i++)
{
c=a+b;
// Next term i.e sum of previous 2 terms
a=b;
b=c;
// Changing terms to new previous terms
cout<<c<<" ";
}
return 0;
}
// Fibonacci series -> 0 1 1 2 3 5 8 13 ......
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run