Write a program to get the 10 values for user & calculate sum and average.
(Learn All Programming and Scripting Languages with youtube.com/avadhtutor/playlists)
Example:
<title>Write a program to get the 10 values for user & calculate sum and average.</title>
<?php
/* Write a program to get the 10 values for user & calculate sum and average. */
$arr1=array(1,2,3,4,5,6,7,8,9,10);
$sum=0;
foreach($arr1 as $arr2=>$arr3)
{
print$arr3."<br>";
$sum=$sum+$arr3;
}
$avg=$sum/10;
print"Sum = ".$sum."<br>";
print"Avrage = ".$avg;
?>
Output:
1
2
3
4
5
6
7
8
9
10
Sum = 55
Avrage = 5.5
2
3
4
5
6
7
8
9
10
Sum = 55
Avrage = 5.5
No comments:
Post a Comment