in reply to Multidimentioal array
it magically works after converting the C-style loops to Perl
Update: ... and strip the attempt at array initialization. I was wondering why the loops were having an effect but failed to notice I automatically fixed the array init. Ups.
Output:#!/usr/bin/perl use strict; use warnings; print " Enter dimension : "; my $n = <STDIN>; $n--; my $k = 1; my @matrix; for my $i (0..$n) { for my $j (0..$n) { $matrix[$i][$j]= $k++; } } print " the matrix : \n\n"; for my $i (0..$n) { for my $j (0..$n) { print "$matrix[$i][$j] "; } print "\n"; }
% perl matrix.pl Enter dimension : 5 the matrix : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Multidimentioal array
by 1nickt (Canon) on Jul 09, 2015 at 12:37 UTC | |
by roboticus (Chancellor) on Jul 09, 2015 at 12:53 UTC | |
by 1nickt (Canon) on Jul 09, 2015 at 15:27 UTC | |
by roboticus (Chancellor) on Jul 09, 2015 at 21:42 UTC | |
by Monk::Thomas (Friar) on Jul 10, 2015 at 08:55 UTC | |
by 1nickt (Canon) on Jul 10, 2015 at 11:22 UTC | |
by Monk::Thomas (Friar) on Jul 10, 2015 at 11:37 UTC | |
|
Re^2: Multidimentioal array
by Subhrangshu Das (Initiate) on Jul 10, 2015 at 07:55 UTC |