kwthrth89
kwthrth89 kwthrth89
  • 18-06-2021
  • Computers and Technology
contestada

find the summation of even number between (2,n)​

Respuesta :

MrRoyal
MrRoyal MrRoyal
  • 24-06-2021

Answer:

The program in python is as follows:

n = int(input("n: "))

sum = 0

for i in range(2,n+1):

   if i%2 == 0:

       sum+=i

print(sum)

Explanation:

This gets input n

n = int(input("n: "))

This initializes sum to 0

sum = 0

This iterates through n

for i in range(2,n+1):

This checks if current digit is even

   if i%2 == 0:

If yes, take the sum of the digit

       sum+=i

Print the calculated even sum

print(sum)

Answer Link

Otras preguntas

Each day that a library book is kept past its due date, a $0.30 fee is charged at midnight. Which ordered pair is a viable solution if x represents the number o
Find the slope of 9x=3y+5
what's the greatest common factor of 21 and 33??
Education helps individual citizens grow, and it B-builds a(n) _____________. A-strong country B-uneducated population C-weak country D-strong voter base
Winston churchled great Britain in world war 1 True False
Which South American country has the highest population density?
What organisms on the food web have the most available energy?
How did Qin rulers unite China?
How a scientist might use a karyotype to study genetic disorders?
26,30,45,43,26,14,28,33,56,29,what is the mean of the data set