要求:数据是有键盘输入的,个数不定。
#! /usr/bin/perl
sub total {
my $sum=0;
while (@_) {
$sum=$sum+pop @_;
}
return $sum;
}
print "Please input some numbers:\n";
$n=&total();
print "the sum of these numbers is $n\n";
#! /usr/bin/perl
sub total {
my $sum=0;
while (@_) {
$sum=$sum+pop @_;
}
return $sum;
}
print "Please input some numbers:\n";
$n=&total();
print "the sum of these numbers is $n\n";
编辑回复