Sum of an arithmetic series

 n = int(input("Enter a number: "))


# Using the formula for the sum of an arithmetic series

sum_of_n_numbers = (n * (n + 1)) // 2

print("Sum of the first", n, "numbers is", sum_of_n_numbers)

In this program, we first take the input `n` from the user. Then we use the formula for the sum of an arithmetic series, which is `(n * (n + 1)) // 2`, to calculate the sum of the first `n` numbers. Finally, we print the result.

Comments

Popular posts from this blog

Ecommerce website

Yes, Python is an object-oriented programming (OOP) language, but it is also a multi-paradigm language

Your task is to find the missing number.