要求:给定一组数据,要求把大于这组数据的平均值的数值打印出来。
#! /usr/bin/perl
sub sum {
my $sum=0;
my @num=@_;
foreach (@num) {
$sum+=$_;
}
$sum;
}
sub average {
my @num=@_;
my $cou=@num;
my $sum=∑(@num);
$sum/$cou;
}
sub av_ab {
my @list;
my $ave=&average(@_);
foreach my $ele (@_) {
if ($ele > $ave) {
print "$ele ";
}
}
}
$a=&av_ab(1..100);
print "$a\n";
#! /usr/bin/perl
sub sum {
my $sum=0;
my @num=@_;
foreach (@num) {
$sum+=$_;
}
$sum;
}
sub average {
my @num=@_;
my $cou=@num;
my $sum=∑(@num);
$sum/$cou;
}
sub av_ab {
my @list;
my $ave=&average(@_);
foreach my $ele (@_) {
if ($ele > $ave) {
print "$ele ";
}
}
}
$a=&av_ab(1..100);
print "$a\n";
编辑回复