Write the program to process a list of numbers?

Answer

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

Perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$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);

All perl Questions

Ask your interview questions on perl

Write Your comment or Questions if you want the answers on perl from perl Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---