﻿ C++ : Calculate the sum of the series 1.2+2.3+3.4+4.5+5.6+…

# C++ Exercises: Calculate the sum of the series 1.2+2.3+3.4+4.5+5.6+.....

## C++ For Loop: Exercise-67 with Solution

Write a program in C++ to calculate the sum of the series 1.2+2.3+3.4+4.5+5.6+.......

Sample Solution:-

C++ Code :

``````#include <iostream>
using namespace std;
int main()
{
int trm;
double num, sum, i, m;
cout << "\n\n calculate the sum of the series 1.2+2.3+3.4+4.5+5.6+......:\n";
cout << "----------------------------------------------------------------\n";
cout << " Input the last integer between 1 to 98 without fraction you want to add: ";
cin >> trm;
for (i = 1; i <= trm; i++)
{
if (i < 9)
{
m = .1;
}
else
{
m = .01;
}
num = i + ((i + 1) * (m));
sum = sum + num;
cout << num;
if (i < trm)
{
cout << " + ";
}
}
cout << "\n The sum of the series =" << sum << endl;
}
``````

Sample Output:

``` calculate the sum of the series 1·2+2·3+3·4+4.5+5.6+......:
----------------------------------------------------------------
Input the last integer between 1 to 98 without fraction you want to ad
d: 10
1.2 + 2.3 + 3.4 + 4.5 + 5.6 + 6.7 + 7.8 + 8.9 + 9.1 + 10.11
The sum of the series =59.61
```

Flowchart: C++ Code Editor: