forked from Priyadarshan2000/Hacktoberfest_2k22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fab.cpp
30 lines (28 loc) · 801 Bytes
/
fab.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream>
using namespace std;
#include<conio.h>
int main()
{
int num1,num2,nextnum,n,i;
cout<<"Enter the value for range:"; //Fibonacci series range value will be inputted
cin>>n;
num1=0;
num2=1;
cout<<"Fibonacci series is:"<<endl;
if(n==1)
cout<<num1<<endl; //Single value will be printed if range value is 1
else if(n==2)
cout<<num1<<"\t"<<num2<<endl; //Two values will be printed if the range value is two
else
{
cout<<num1<<"\t"<<num2<<"\t";
for(i=3;i<=n;i++) //Fibonacci series will be printed based on range limit
{
nextnum=num1+num2;
cout<<nextnum<<"\t";
num1=num2;
num2=nextnum;
}
}
getch();
}