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:
Contribute your code and comments through Disqus.
Previous: Write code to create a checkerboard pattern with the words "black" and "white".
Next: Write a program that will print the first N numbers for a specific base.
What is the difficulty level of this exercise?
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join