我的节目是 -
@arr=('1','1 1');
print "enter the number of rows\n";
$rows=<STDIN>;
$v=0;
while($v<$rows)
{
foreach $ele (@arr)
{
@arr1=split(/\s+/,$ele);
$g=@arr1;
#print "$g\n";
$i=0;
$j=1;
$str='';
while ($j<$g)
{
$res=$arr1[$i]+$arr1[$j];
#print "$res\n";
$i=$1+1;
$j=$j+1;
$str=$str.' '.$res;
}
$final='1'.' '.$str.' '.'1';
print "$final\n";
}
$v=$v+1;
#@arr=();
push(@arr,$final);
}
print "@arr";
foreach (@arr)
{
print "$_\n";
}
我的输出是:
C:\Perl\bin>perl pascal.pl
enter the number of rows
4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 8 5 1
最后一行的8应该是10.但为什么它会来8?
答案 0 :(得分:7)
答案 1 :(得分:1)
我做了一个拼写错误。而不是$ i = $ i + 1,我有$ i = $ 1 + 1.