4 of 4
➕ Operators 🔂 Loops
➕ Operators
🔂 Loops
Write a program that asks the user for a number n, then computes and prints the sum:
n
∑i=1n−1i=1+2+3+⋯+(n−1)\sum_{i=1}^{n-1} i = 1 + 2 + 3 + \cdots + (n-1)∑i=1n−1i=1+2+3+⋯+(n−1)
Example: When n = 10:
n = 10
∑i=19i=45\sum_{i=1}^{9} i = 45∑i=19i=45
Use a loop (or the formula (n-1) * n // 2) to compute it.
(n-1) * n // 2
Enter n: 10 45
Previous
Find the Minimum