Write a perl program to find average of numbers entered in user defined list
Answers
Answered by
15
#usr/bin/perl
use strict;
use warnings;
my $a; #variable declaration
my $b; #variable declaration
my $c; #variable declaration
my $avg; #variable declaration
my $x; #variable declaration
my $y; #variable declaration
my $z; #variable declaration
my $results; #variable declaration
my $number; #variable declaration
$a = 2; #number 1
$b = 6; #number 2
$c = 7; #number 3
$avg = avg($a,$b,$c); #Three variables to be averaged
sub avg {
($x,$y,$z) = @_; #Store variables in array
$results = ($x+$y+$z)/3; #Values stored added, and divided for average
return $results; #return value
}
print "$avg\n";
exit;
BrainlyTech:
1 sec
Similar questions
Math,
7 months ago
Physics,
7 months ago
Biology,
7 months ago
Computer Science,
1 year ago
English,
1 year ago