220k views
2 votes
Write a program to calculate and print the sum of numbers from 1 to 15, including both. using a loop.

1 Answer

2 votes

Final answer:

A simple program in Python, for instance, initializes a sum variable, iterates over the numbers 1 to 15 with a for loop, and adds each number to the sum, which is then printed out.

Step-by-step explanation:

Program to Calculate Sum from 1 to 15

To calculate the sum of numbers from 1 to 15 using a loop, you can write a simple program in many programming languages. Here is an example in Python:

sum = 0
for number in range(1, 16):
sum += number
print('The sum of numbers from 1 to 15 is:', sum)

This program initializes a variable sum to 0 and then iterates over a range of numbers from 1 to 15 inclusive. During each iteration of the loop, the current number is added to the sum. After the loop completes, the sum is printed out.

User Lennoard Silva
by
8.0k points

No related questions found