用perl语言 随机生成100道100以内加减乘除法题目,一行4个
1个回答
展开全部
for (1..100)
{
print rand100(), "=? ";
print "\n" if ($_%4 == 0);
}
sub rand100{
my $op = int(rand(4));
my ($m, $n);
while (1) {
$m = int(rand(50))+1;
if ($op == 0) {
$n = int(rand(100-$m))+1;
return "$m+$n";
}
elsif ($op == 1) {
$n = int(rand(100))+1;
return "$n-$m" if ($m < $n);
return "$m-$n";
}
else {
$n = int(rand(100/$m))+1;
next if ($m == 1 || $n == 1);
return "$m*$n" if($op == 2);
$m = $m*$n;
return "$m/$n";
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询