Chinaunix首页 | 论坛 | 博客
  • 博客访问: 222192
  • 博文数量: 50
  • 博客积分: 1415
  • 博客等级: 上尉
  • 技术积分: 541
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-03 11:48
文章分类

全部博文(50)

文章存档

2010年(38)

2009年(12)

我的朋友

分类:

2009-12-09 12:41:19

#!user/bin/perl

use strict;
my @fred = qw /1 3 5 7 9/;
my $fred = total(@fred);
print "The total of \@fred is $fred \n";

print "enter some number in separate lines \n";
print "you can use Ctrl\+z stop enter \n";
my $user_total = total(<STDIN>);
print "the total of those number is $user_total \n";
my @num = (0..1000);
my $num = total(@num);
print "the total of 1-1000 is $num\n";

sub total {
my (@arg) = @_;
my $total;
foreach (0..$#arg) {

$total += $arg[$_];
}
return $total;
}
<STDIN>;


阅读(745) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~