I need some help with a problem.
Problem: Using a for loop, compute the average of the first 20 odd numbers. Print only the average.
I have figured out how to count the first 20 odd numbers in the for loop but I can't figure out how to get the average where it only prints the average. Right now it is printing the total of all the odd numbers of 400.
Any help would be greatly appreciative. Also, if you could explain in simple terms as I am a beginner. Thanks!
{
$avg=0
for ($i =1 ; $i –le 39 ; $i+=2) {
$avg = $avg +$i
}
echo $avg
}