-
Notifications
You must be signed in to change notification settings - Fork 0
/
series.cpp
138 lines (113 loc) · 1.82 KB
/
series.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
class series{
public:
int s1=0,s2=0,s4=0,s6=1,s7=1,s8=0;
float s3=0,s5=0;
void sum1(int n)
{
for(int i=1;i<=n;i++)
{
s1=s1+i;
}
cout<<"sum1="<<s1<<endl;
}
void sum2(int n1,int n2)
{
int a=1,b=2;
while(a<=n1 && b<=n2)
{
s2=s2+a*b;
a=a+1;
b=b+1;
}
cout<<"sum2="<<s2<<endl;
}
void sum3(float n)
{
for(float i=1.5;i<=n;i++)
{
s3=s3+i;
}
cout<<"sum3="<<s3<<endl;
}
void sum4(int n)
{
for(int i=1;i<=n;i++)
{
s4=s4+i*i;
}
cout<<"sum4="<<s4<<endl;
}
void sum5(int n)
{
for(float i=1;i<=n;i++)
{
s5=s5+(1/i);
}
cout<<"sum5="<<s5<<endl;
}
void sum6(int n)
{
for(int i=1;i<=n;i++)
{
s6=s6*i;
}
cout<<"sum6="<<s6<<endl;
}
void sum7(int n)
{
for(int i=1;i<=n;i++)
{
s7=s7*pow(i,2);
}
cout<<"sum7="<<s7<<endl;
}
void sum8(int n)
{
for(int i=1;i<=n;i++)
{
if(i%2==0)
{
s8=s8-i;
}
else{
s8=s8+i;
}
}
cout<<"sum8="<<s8<<endl;
}
void fibonacci(int n)
{
int first=0,second=1,fibo,r=0;
while(r<n)
{
if(r<=1)
{
fibo=r;
}
else{
fibo=first+second;
first=second;
second=fibo;
}
cout<<fibo<<" ";
r++;
}
}
};
int main(){
series s;
s.sum1(4); //1+2+3+.......+n
s.sum2(4,5); //1*2+2*3+3*4*5
s.sum3(4);//1.5+2.5+3.5+...+n
s.sum4(4);//1^2+2^2+3^2+...+n^2
s.sum5(4);//1+1/2+1/3+1/4+...+1/n
s.sum6(4);//1*2*3*4*5....*n
s.sum7(3);//1^2*2^2*.....*n^2
s.sum8(4);//1-2+3-4+....
s.fibonacci(7);//0 1 1 2 3 5 8
getch();
}