且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Leaning perl 第2章练习题答案

更新时间:2022-09-19 14:43:00

原文发表在网易博客 2010-11-04 21:18:43

开始学习perl了,得多做题啊.

Leaning perl 第2章练习题答案(让我对perl感兴趣的是小羊驼书,呃这个就是羊驼了,不过怎么感觉跟网络上某个神兽很像啊.)

2.1-2.3 计算圆半径计算

#!perl -w 
$PI=3.141592654; 
print "ENTER the semidiameter:"; 
$semidiameter = <STDIN> ; 
chomp($semidiameter); 
if ($semidiameter < 0  ){ 
    $semidiameter=0; 
    } 
$circumference=2*$PI*$semidiameter; 
print "circumference is $circumference";

 

2.4计算两个数字的积 
#!perl -w

print "Enter the first number(a):"; 
chomp($a=<STDIN>); 
print "Enter the second number(b):"; 
chomp($b=<STDIN>); 
$c=$a*$b; 
print "a*b is $c";

2.5 将某个字符串打印一定次数

#!perl -w 
print "Enter the character to print:"; 
chomp($string_to_print=<STDIN>); 
print "Enter times to print:"; 
chomp($times=<STDIN>); 
$result=${string_to_print} x $times; 
print "result is :$result";

    2011-05-25 22:33 
    感谢大家的鼓励,这篇文章发表在网易博客上之后有人回复我哦.



本文转自leipei博客园博客,原文链接:http://www.cnblogs.com/leipei2352/archive/2011/05/25/2057465.html,如需转载请自行联系原作者