Programming Languages C++ Subjective
Mar 13, 2013

Write the program to process a list of numbers.

Detailed Explanation

The following program would ask the user to enter numbers when executed and the average of the numbers is shown as the output:


$sum = 0;
 
$count = 0;
 
print "Enter number: ";
 
$num = <>;
 
chomp($num);
 
while ($num >= 0)
 
{
 
$count++;
 
$sum += $num;
 
print "Enter another number: ";
 
$num = <>;
 
chomp($num);
 
}
 
print "$count numbers were entered\n";
 
if ($count > 0)
 
{
 
print "The average is ",$sum/$count,"\n";
 
}
 
exit(0);

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback