177k views
1 vote
Write code using the range function to add up the series 99, 98, 97,...

1 and print the resulting sum.
Expected Output
4950

User Lkrups
by
6.1k points

1 Answer

2 votes

Answer:

This program is written in python;

Comments are used for explanatory purpose;

Take note of indentations (See picure attachment)

Program starts here

#Initialize Sum to 0

sum = 0

#Iterate from 99 to 1 using range function

#The iterating variable i starts from 99 and ends at 1 with a difference of -1

for i in range(99, 1, -1):

sum+=i

#Display Result

print("Expected Output: ",sum)

#End of Program

Write code using the range function to add up the series 99, 98, 97,... 1 and print-example-1
User Taha Zgued
by
6.3k points