can anyone help me with this question please ?
write a program to compute the average of the ten numbers 1,4,9,...,81,100, that is, the average of the squares of the numbers from 1 to 10. (Hint: instead of printing each squares as it is computed, add it in to a variable sum which keeps track of the sum of all the squares, and then at the end, divide the sum variable by the number of numbers summed.)
if you keep track of the sum in a variable of type int, and divide by the integer 10, you'll get an integer-only approximation of the average (the answer should be 38). If you keep track of the sum in a variable of type float or double, on the other hand, you will get the answer as a floating-point number.
HERE IS WHAT I HAVE SO FAR AND I DON'T KNOW WHAT ELSE TO DO , ANY HELP WILL BE VERY MUCH APPRECIATE. "I'm new to coding"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
int main()
{
int i;
float sum = 0;
int n = 0;
for (i = 1; i <=10; i = i + 1)
{
sum = sum + i * i;
n = n + 1;
}
printf("The average is %f\n", sum/n);
return 0;
|
}