I was trying to write the program of magic square. So I need a dynamic 2D array. But however when I tried to put some number in the array, it behaves abnormally. the output shows the first 2 rows as identical... my code was...
################################################### #!/usr/bin/perl use warnings; print " Enter dimension : "; my $n = <STDIN>; my $i=0; my $j=0; my $k=1; my @matrix = ( $n , $n ); for($i = 0; $i < $n; $i++) { print " see how the first row changes automatically...\n\n"; for($j = 0; $j < $n; $j++) { $matrix[$i][$j]= $k++; print "row = $i and col = $j input = $matrix[$i][$j] firstrow $j = $m +atrix[0][$j] //for error checking \n"; } } print " the matrix : \n\n"; for($i = 0; $i < $n; $i++) { for($j = 0; $j < $n; $j++) { print "$matrix[$i][$j] "; } print "\n"; } ############################################
just check it out
In reply to Multidimentioal array by Subhrangshu Das
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |