-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfibonacci.cpp
67 lines (61 loc) · 1.24 KB
/
fibonacci.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
using namespace std;
void name(){
cout<<'Author: Varun Gupta'<<endl;
}
//4. Printing the fibonacci series using recursion.
int Fib_Series(int x1)
{
static int a1=0,a2=1,a3;
int count=2;
if(x1>=1)
{
a3=a1+a2;
cout<<a3<<" ";
a1=a2;
a2=a3;
return Fib_Series(x1-1);
}
cout<<endl;
return 0;
}
int main(){
name();
//Implementing fibonacci series using different methods.
int a1=0,a2=1,a3,limit,count;
cout<<"Enter the limit of fibonacci series "<<endl;
cin>>limit;
cout<<a1<<" "<<a2<<" ";
// for(int count=2;count<limit;count++)
// {
// a3=a1+a2;
// cout<<a3<<" ";
// a1=a2;
// a2=a3;
// }
// cout<<endl;
//While Loop
count=2;
// while(count<limit)
// {
// a3=a1+a2;
// cout<<a3<<" ";
// a1=a2;
// a2=a3;
// count++;
// }
// Using do-while Loop.
// do
// {
// a3=a1+a2;
// cout<<a3<<" ";
// a1=a2;
// a2=a3;
// count++;
// }
// while (count<limit);
// cout<<endl;
//Using the process of recursion.
Fib_Series(limit-2);
return 0;
}