rfcv 发表于 2015-12-28 08:03:14

Leaning perl 第2章练习题答案

  原文发表在网易博客 2010-11-04 21:18:43
  开始学习perl了,得多做题啊.
(让我对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 &quot;circumference is $circumference&quot;;
  
  2.4计算两个数字的积   
#!perl -w
  print &quot;Enter the first number(a):&quot;;   
chomp($a=<STDIN>);   
print &quot;Enter the second number(b):&quot;;   
chomp($b=<STDIN>);   
$c=$a*$b;   
print &quot;a*b is $c&quot;;
  2.5 将某个字符串打印一定次数
  #!perl -w   
print &quot;Enter the character to print:&quot;;   
chomp($string_to_print=<STDIN>);   
print &quot;Enter times to print:&quot;;   
chomp($times=<STDIN>);   
$result=${string_to_print} x $times;   
print &quot;result is :$result&quot;;
  2011-05-25 22:33   
    感谢大家的鼓励,这篇文章发表在网易博客上之后有人回复我哦.
页: [1]
查看完整版本: Leaning perl 第2章练习题答案