Write an algorithm To display sum of first 10 even numbers
Answers
Answered by
0
Answer:
total = 0
for number in range(1, 21):
if(number % 2 == 0):
print("{0}".format(number))
total = total + number
print(total)
Explanation:
Assuming the question is python related, the above thing should work
First, we declare "total" as a variable with a value of zero
then we start a for loop, where starting number is 1 and last number is 20 (20 + 1 because range gives last number - 1 as output)
20 because 2 × 10 = 20 (first 10 even numbers)
then we check that the numbers between 1 to 20 divided by 2 leave the remainder as zero, if they do then that's an even number and we pick it
then we add the numbers
and then we print the total
Similar questions