QuestionAugust 10, 2025

Write the code using a for loop that finds the average of all the integers between 10-50

Write the code using a for loop that finds the average of all the integers between 10-50
Write the code using a for loop that finds the average of all the integers between 10-50

Solution
4.6(366 votes)

Answer

The average is 30.0 Explanation 1. Initialize Variables Set `total_sum` to 0 and `count` to 0 for accumulating sum and counting numbers. 2. Iterate Over Range Use a for loop to iterate from 10 to 50 inclusive. 3. Accumulate Sum and Count Add each number to `total_sum` and increment `count` by 1. 4. Calculate Average Divide `total_sum` by `count` to find the average.

Explanation

1. Initialize Variables<br /> Set `total_sum` to 0 and `count` to 0 for accumulating sum and counting numbers.<br />2. Iterate Over Range<br /> Use a for loop to iterate from 10 to 50 inclusive.<br />3. Accumulate Sum and Count<br /> Add each number to `total_sum` and increment `count` by 1.<br />4. Calculate Average<br /> Divide `total_sum` by `count` to find the average.
Click to rate:

Similar Questions