输入变量与if

2016-10-11 19:54:34来源:CSDN作者:g13731463274人点击

[root@mysql1 perl]# cat 11.pl  
#!/usr/bin/perl -w


$pi=3.141592654;
print "what is the radius? ";
chomp($radius=<STDIN>);
$circ=2 * $pi * $radius;
if($radius<0) {
$circ=0;
}
print "the circumference of a circle of radius $radius is $circ./n";


[root@mysql1 perl]# ./11.pl   
what is the radius? 1
the circumference of a circle of radius 1 is 6.283185308.
[root@mysql1 perl]# ./11.pl 
what is the radius? 2
the circumference of a circle of radius 2 is 12.566370616.
[root@mysql1 perl]# ./11.pl -1
what is the radius? -1
the circumference of a circle of radius -1 is 0.
[root@mysql1 perl]# ./11.pl
what is the radius? -2
the circumference of a circle of radius -2 is 0.

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台