-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut18.cpp
84 lines (69 loc) · 2.33 KB
/
tut18.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
77
78
79
80
81
82
83
84
#include<iostream>
using namespace std;
void name(){
cout<<'Author: Varun Gupta'<<endl;
}
// int gen(int n)
// {
// if(n<=1){
// return 1;
// }
// return (n *gen(n-1));
// }
// Step by step calculation of recursion function:
// gen(4)= 4*gen(3);
// gen(4)= 4*3*gen(3);
// gen(4)= 4*3*2*gen(3);
// gen(4)= 4*3*2*1;
// gen(4)= 24;
int fib(int f)
{
int g;
if(f<=1)
{
return 1;
}
return fib(f-2)+fib(f-1);
}
int main(){
name();
// int a, b, fact=1;
// Factorial of a number using for loop.//
// cout<<"Enter the number for which you want to generate factorial"<<endl;
// cin>>a;
//Factorial of a number in ascending order.//
// for(b=1;b<=a;b++)
// {
// fact=fact*b;
// }
// cout<<"The factorial of :"<<a<<" is "<<fact<<endl;
//Factorial of a number in decreasing order.//
// for(b=a;b>=1;b--)
// {
// fact=fact*b;
// }
// cout<<fact<<endl;
//Factorial of a number using recursion.//
// cout<<"The factorial of a is \n"<<gen(a)<<endl;
//Fibonacci series using for loop.
// while(a=0)
// {
// b++;
// }
int e;
cout<<"Enter the position for which you want to see the values in fibonacci series "<<fib(e)<<endl;
// Program to generate fibonacci series.
int a1=0, a2=1, a3, limit, count;
cout<<"Enter the limit of the fibonacci series :"<<endl;
cin>>limit;
cout<<a1<<a2;
for(count=2;count<limit;count++)
{
a3=a1+a2;
cout<<a3<<endl;;
a1=a2; //The a1 i.e 0 is assigned the value of a2 i.e 1.
a2=a3; // The a2 is assigned the values of a3 i.e a1+a2 = 1.
// And that's how the value of instances gets updated in every instance.
}
return 0;
}