#!/usr/bin/perl
use warnings;
use strict;
sub sub_max{
my $sum;
foreach (@_){
$sum += $_;
}
print "总和是: $sum \n";
$sum;
}
&sub_max(1,2,3,4,5,6,7,8,9);
my @fred = qw{1 3 5 7 9};
my $fred_total = sub_max(@fred);
print "The total of \@fred is $fred_total.\n";
print "Enter some numbers on separate lines: \n";
#下面的输入, 每输入一个数, 要按一次回车
my $user_total = sub_max(<STDIN>);
print "The total of those numbers if $user_total\n";
PERL语言入门:第四章:子程序(函数):习题1:写一个程序, 求所有参数的和
最新推荐文章于 2021-10-17 21:21:22 发布