Skip to content

Commit b03b7e6

Browse files
Calculate the given Series
1 parent 546823f commit b03b7e6

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

CalculateTheGivenSeries.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//C++ program to find the sum of the series (1)+(1+2)+(1+2+3)+(1+2+3+...+n)
2+
3+
#include <iostream>
4+
5+
using namespace std;
6+
7+
int main()
8+
9+
{
10+
11+
int i, j, n, sum, total = 0;
12+
13+
cout << "Enter the value for nth term: ";
14+
15+
cin >> n;
16+
17+
for (i = 1; i <= n; i++)
18+
19+
{
20+
21+
sum = 0;
22+
23+
for (j = 1; j <= i; j++)
24+
25+
{
26+
27+
total += j;
28+
29+
sum += j;
30+
31+
cout << j;
32+
33+
if (j < i)
34+
35+
{
36+
37+
cout << "+";
38+
39+
}
40+
41+
}
42+
43+
cout << " = " << sum << endl;
44+
45+
}
46+
47+
cout << "\nThe sum of the above series is: " << total << endl;
48+
49+
}

0 commit comments

Comments
 (0)