Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a program to calculate the average of natural number from 1 to 50

0 votes
asked May 13, 2019 by Priti Verma (120 points)

3 Answers

+1 vote
answered May 13, 2019 by [email protected]
x=0
for i in range(51):
    x+=i
print(x/50)
+2 votes
answered May 13, 2019 by anonymous
sum=n*(n+1)/2;

avg=sum/n;
–1 vote
answered Jun 22, 2019 by Robert Parry (240 points)
sum of numbers from 1 to 50 is (50*51)/2 = 25*51

average = 51/2 but that is not an integer, so you'll need to do 51.0/2.0
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...