-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFIBONACII.CPP
76 lines (69 loc) · 1.02 KB
/
FIBONACII.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
68
69
70
71
72
73
74
75
76
#include<iostream.h>
#include<conio.h>
int fab1(int n)
{
if(n==1)
{
return 1;
}
if(n==0)
{
return 0;
}
else
{
return(fab1(n-1)+fab1(n-2));
}
}
void fab2(int n)
{
int a=1,b=1,c=1;
for(int i=3;i<n;i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<" ";
}
}
void main()
{
int i=0,n,ch,temp;
here:
clrscr();
cout<<"Choose:-\n\n"
<<"\n1) Recursion"
<<"\n2) Iteration\n";
cin>>ch;
clrscr();
cout<<"Enter no of terms: ";
cin>>n;
if(ch==1)
{
cout<<"\nFebonaki series is as follows (recursion):-\n";
while(i<n)
{
cout<<fab1(i)<<" ";
i++;
}
}
if(ch==2)
{
cout<<"\nFebonaki series is as follows (iteration):-\n";
if(n==1)
cout<<"0";
if(n==2)
cout<<"0 1";
if(n==3)
cout<<"0 1 1";
if(n>3)
{
cout<<"0 1 1 ";
fab2(n);
}
}
cout<<"\n\nEnter 1 to enter again, 2 to exit.";
cin>>ch;
if(ch==1)
goto here;
}