C++ : Calculate The Series (1) + (1+2) + … + (1+2+3+...+n)
C++ Exercises: Calculate the series (1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n)
Last update on November 20 2025 12:17:11 (UTC/GMT +8 hours)
13. Sum of the Series (1) + (1+2) + ... + (1+2+...+n)
Write a program in C++ to calculate the series (1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n).
Visual Presentation:
Sample Solution :-
C++ Code :
#include <iostream> // Including the input/output stream header file using namespace std; // Using the standard namespace to avoid writing std:: int main() // Start of the main function { int i, j, n, sum = 0, tsum; // Declaration of integer variables 'i', 'j', 'n', 'sum', and 'tsum' // Display a message to find the sum of the series (1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n) cout << "\n\n Find the sum of the series (1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n):\n"; cout << "------------------------------------------------------------------------------------------\n"; // Prompt the user to input the value for the nth term of the series cout << " Input the value for nth term: "; cin >> n; // Read the value entered by the user for (i = 1; i <= n; i++) // Outer loop to iterate from 1 to 'n' { tsum = 0; // Initializing 'tsum' to 0 for each iteration of the outer loop for (j = 1; jTừ khóa » C++ 1 2
-
C++ Why Does ((1 / 2) * 2) Return 0 [duplicate] - Stack Overflow
-
1%2 - Modulus Question - C++ Forum
-
C++ Basics - C++ Programming Tutorial
-
Is .5 Equal To 1/2 In The C Language? - Quora
-
Modulo Operator (%) In C/C++ With Examples - GeeksforGeeks
-
A Short Introduction To Computer Programming, Using C++
-
BASICs Of C/C++ Programming
-
10 Common Programming Mistakes In C++ 1 - UCR CS
-
C++ Program To Calculate Sum Of Natural Numbers - Programiz
-
4. Basic Declarations And Expressions - Practical C++ Programming ...
-
Plus One - LeetCode
-
1/2 Should Not Equal Zero - Musing Mortoray
-
C++ Program To Find Nth Term Of The Series 1, 1, 2, 6, 24…
-
[PDF] Some Practice Problems For The C++ Exam And Solutions For The ...