Amrit Kaur

Greenhorn

Posts: 10

posted 7 months ago

hello can i know how you can get the average of first 100 numbers. i have the code of the sum of first 100,now how am i to get the average? can i have the average displayed only and not the other total sum? here is what i have done can i be helped please? and if i have to put the average in double only,not the sum..

Vasyl Lyashkevych

Ranch Hand

Posts: 70

Vasyl Lyashkevych

Ranch Hand

Posts: 70

posted 7 months ago

- 1

Hi Vasyl,

This is incorrect. You need to take a sum of all the numbers and then divide it by the quantity to get the average.

Btw, your program gives the following output:

5050.0

Which is not the average of first 100 numbers as asked by OP.

Hi Amrit,

Rather than writing code, can you explain how you would calculate the average of first 100 or lets say first 10 numbers on paper ?

Vasyl Lyashkevych wrote:Of course you need to count all numbers and later divide them by quantity

This is incorrect. You need to take a sum of all the numbers and then divide it by the quantity to get the average.

Btw, your program gives the following output:

5050.0

Which is not the average of first 100 numbers as asked by OP.

Hi Amrit,

Rather than writing code, can you explain how you would calculate the average of first 100 or lets say first 10 numbers on paper ?

I agree. Here's the better link: Salvin.in

Vasyl Lyashkevych

Ranch Hand

Posts: 70

Consider Paul's rocket mass heater. |