Create a two-dimensional array at runtime: Difference between revisions

From Rosetta Code
Content added Content deleted
(revert spam)
mNo edit summary
Line 1: Line 1:
[http://klohy.info/img/styles/nvidia-gf.htm nvidia gf 6200 128mb] [http://polex.com.cn/resources/articles/the-moon.htm the moon italian version] [http://xionny.cn/topic/philips-webcam/ philips webcam toucam] [http://xionny.cn/topic/monitor-sony/ monitor sony 15] [http://funkall.us/images/small/kan-kun/ kan kun] [http://wedner.info/content/view/masterizzatore-dvd.htm masterizzatore dvd pioneer] [http://funkall.us/images/small/feroza-daihatsu/ feroza daihatsu] [http://funkall.us/images/small/volvo-s/ volvo s40 argento] [http://manoke.cn/topic/lg-dvd/ lg dvd home teatre] [http://wedner.info/content/view/www-republica.htm www republica] [http://manoke.cn/topic/tv-color/ tv color lcd 30] [http://joperan.org/data/samsung-miniket/ samsung miniket vp] [http://manoke.cn/topic/estadio-w/ estadio w] [http://xionny.cn/topic/phil-ochs/ phil ochs] [http://polex.com.cn/resources/articles/forni-a.htm forni a microonde con grill] [http://klohy.info/img/styles/lezioni-di.htm lezioni di impianti tecnici vol 2] [http://polex.com.cn/resources/articles/il-soldino.htm il soldino] [http://soler.net.cn/data/birago.htm birago] [http://wedner.info/content/view/resurrectio.htm resurrectio] [http://polex.com.cn/resources/articles/cd-kenwood.htm cd kenwood] [http://svike.info/view/new/online-dating.htm online dating ads] [http://wedner.info/content/view/la-casa.htm la casa tra le stelle. i segreti della nuova stazione spaziale. la macchina del...] [http://budget7i.info/lib/foto-di/ foto di donne con polpacci grandi] [http://manoke.cn/topic/lexmark-toner/ lexmark toner x215] [http://manoke.cn/topic/fonderia-crespi/ fonderia crespi] [http://svike.info/view/new/falafel.htm falafel] [http://svike.info/view/new/foto-baby.htm foto baby h] [http://budget7i.info/lib/fax-brother/ fax brother 8070p] [http://soler.net.cn/data/ti-c.htm ti c ha mai mandato] [http://xionny.cn/topic/linea-effe/ linea effe snc] [http://soler.net.cn/data/carmen-villani.htm carmen villani] [http://polex.com.cn/resources/articles/racconti-erotici.htm racconti erotici di zie] [http://budget7i.info/lib/summit/ summit] [http://polex.com.cn/resources/articles/calendario-veline.htm calendario veline] [http://manoke.cn/topic/semolei/ semolei] [http://funkall.us/images/small/www-termae/ www termae info] [http://klohy.info/img/styles/hp-laser.htm hp laser 1160] [http://xionny.cn/topic/funkee-green/ funkee green dogs] [http://svike.info/view/new/volo-mont.htm volo mont saint michel] [http://funkall.us/images/small/aspirapolvere-lavor/ aspirapolvere lavor zeus] [http://klohy.info/img/styles/honduras.htm honduras] [http://klohy.info/img/styles/oakley-a.htm oakley a wire 2 0] [http://klohy.info/img/styles/yamaha-nsc.htm yamaha ns-c515] [http://xionny.cn/topic/www-imprenditoria/ www imprenditoria femminile it] [http://joperan.org/data/suse-peluche/ suse peluche] [http://sneck.info/data/calcio-ps/ calcio ps2 videogiochi] [http://budget7i.info/lib/gang-/ gang bang] [http://funkall.us/images/small/turner-vegas/ turner vegas 1200] [http://joperan.org/data/il-capo/ il capo regala un sistema audio professionale samsung] [http://primonona.info/content/view/denon-pmar/ denon pma-655r] [http://svike.info/view/new/ricoh.htm ricoh 4000] [http://polex.com.cn/resources/articles/plotter-hp.htm plotter hp designjet a1] [http://xionny.cn/topic/ottimo-avvio/ ottimo avvio di gran turismo 3 in italia] [http://polex.com.cn/resources/articles/fz.htm fz 30] [http://xionny.cn/topic/bowlinng/ bowlinng] [http://manoke.cn/topic/trevi-tv/ trevi tv] [http://primonona.info/content/view/alta-marea/ alta marea a mezzogiorno] [http://sneck.info/data/la-fine/ la fine di troia nel racconto di enea] [http://sneck.info/data/mp-u/ mp3 u2] [http://polex.com.cn/resources/articles/renaultsport.htm renaultsport] [http://wedner.info/content/view/wangan.htm wangan] [http://funkall.us/images/small/hip-hop/ hip hop collection] [http://budget7i.info/lib/dernier-danse/ dernier danse] [http://funkall.us/images/small/guardami-film/ guardami film] [http://primonona.info/content/view/rebel-moves/ rebel moves bandare] [http://wedner.info/content/view/foto-annuncio.htm foto annuncio amatoriale] [http://veggis.org.cn/resources/articles/nice.htm n.i.c.e. 2] [http://soler.net.cn/data/sms-win.htm sms win] [http://sneck.info/data/tucano-neonato/ tucano neonato] [http://manoke.cn/topic/e-va/ e va albert sordi] [http://veggis.org.cn/resources/articles/john-jeans.htm john jeans] [http://svike.info/view/new/duncan-james.htm duncan james e keedie i believe my heart] [http://budget7i.info/lib/candida/ candida] [http://xionny.cn/topic/testo-della/ testo della canzone the reason] [http://xionny.cn/topic/calvignasco/ calvignasco] [http://primonona.info/content/view/enne/ enne] [http://budget7i.info/lib/je-t/ je t aime ma non plus] [http://soler.net.cn/data/anima-dvd.htm anima dvd] [http://sneck.info/data/apprendere-in/ apprendere in rete] [http://polex.com.cn/resources/articles/dragostea-din.htm dragostea din tei di] [http://xionny.cn/topic/palm-phone/ palm phone] [http://svike.info/view/new/lenny-kravitz.htm lenny kravitz calling all angel] [http://xionny.cn/topic/don-giovanni/ don giovanni di mozart] [http://polex.com.cn/resources/articles/sagre-ciliegia.htm sagre ciliegia] [http://xionny.cn/topic/pelicula-titanic/ pelicula titanic] [http://xionny.cn/topic/dissipatori-memorie/ dissipatori memorie] [http://veggis.org.cn/resources/articles/donkie-kong.htm donkie kong] [http://budget7i.info/lib/calenda-maia/ calenda maia] [http://manoke.cn/topic/calendario-delle/ calendario delle casalinghe] [http://veggis.org.cn/resources/articles/pioneer.htm pioneer 50] [http://veggis.org.cn/resources/articles/ipod-diffusori.htm ipod diffusori] [http://xionny.cn/topic/concessionaria-rover/ concessionaria rover] [http://klohy.info/img/styles/morwa.htm morwa] [http://xionny.cn/topic/ultimi-video/ ultimi video di spears] [http://klohy.info/img/styles/www-italeri.htm www italeri com] [http://primonona.info/content/view/target-moda/ target moda] [http://joperan.org/data/reinas-del/ reinas del mediodia] [http://polex.com.cn/resources/articles/mp-messicani.htm mp3 messicani da scaricare] [http://svike.info/view/new/beegees-staying.htm beegees staying alive mp3] [http://sneck.info/data/bratz-babyz/ bratz babyz] [http://polex.com.cn/resources/articles/smash-court.htm smash court tennis] [http://soler.net.cn/data/i-miei.htm i miei sei forzati] [http://primonona.info/content/view/mesenzana/ mesenzana] [http://xionny.cn/topic/stradario-italia/ stradario italia] [http://svike.info/view/new/dragoball-z.htm dragoball z] [http://funkall.us/images/small/bambola-hard/ bambola hard] [http://joperan.org/data/bozen/ bozen] [http://funkall.us/images/small/llanos/ llanos] [http://svike.info/view/new/testo-scusami.htm testo scusami d alessio] [http://primonona.info/content/view/gellner-libri/ gellner libri] [http://klohy.info/img/styles/behringer-guitar.htm behringer guitar pack] [http://klohy.info/img/styles/pettorano.htm pettorano] [http://primonona.info/content/view/captain-/ captain america] [http://xionny.cn/topic/he-shape/ he shape of my hear] [http://svike.info/view/new/ram-a.htm ram a] [http://veggis.org.cn/resources/articles/fiat-marea.htm fiat marea km 0] [http://svike.info/view/new/e-casa.htm e casa] [http://veggis.org.cn/resources/articles/frigorifero-style.htm frigorifero style] [http://xionny.cn/topic/soluzioni-e/ soluzioni e trucchi] [http://primonona.info/content/view/sorrisa/ sorrisa] [http://svike.info/view/new/toyota-avensis.htm toyota avensis sw] [http://soler.net.cn/data/basso-yamaha.htm basso yamaha] [http://veggis.org.cn/resources/articles/nhun.htm nhun] [http://xionny.cn/topic/audi-a/ audi a3 toscana] [http://joperan.org/data/foto-di/ foto di ragazze nude] [http://sneck.info/data/cameron-dias/ cameron dias] [http://manoke.cn/topic/programma-windows/ programma windows media playar] [http://polex.com.cn/resources/articles/flinta.htm flinta] [http://joperan.org/data/il-duomo/ il duomo assicurazioni] [http://xionny.cn/topic/gps-vista/ gps vista] [http://primonona.info/content/view/weekend-lunghi/ weekend lunghi al mare] [http://funkall.us/images/small/telefax-segreteria/ telefax segreteria] [http://xionny.cn/topic/xcleaner/ x-cleaner] [http://manoke.cn/topic/breezin/ breezin] [http://wedner.info/content/view/neffa-come.htm neffa come mai] [http://primonona.info/content/view/scott-speedman/ scott speedman] [http://manoke.cn/topic/italia-sardegna/ italia sardegna vacanze in] [http://klohy.info/img/styles/videogiochi-pc.htm videogiochi pc yu gi ho] [http://polex.com.cn/resources/articles/dka-tylko.htm dka tylko ty kochanie] [http://primonona.info/content/view/teach-you/ teach you childres] [http://polex.com.cn/resources/articles/ww-virginio.htm ww virginio it] [http://funkall.us/images/small/tutta-dance/ tutta dance 11] [http://manoke.cn/topic/varadero/ varadero 1000] [http://soler.net.cn/data/il-terribile.htm il terribile ispettore] [http://veggis.org.cn/resources/articles/hauptmann-gerhart.htm hauptmann, gerhart] [http://svike.info/view/new/index.htm index2] [http://polex.com.cn/resources/articles/tumino-giovanni.htm tumino giovanni] [http://wedner.info/content/view/i-termini.htm i termini piu ricercati] [http://veggis.org.cn/resources/articles/x-agp.htm x800 agp 256] [http://svike.info/view/new/ogrish.htm ogrish] [http://sneck.info/data/ibiza-/ ibiza 1999 seat] [http://klohy.info/img/styles/cellulare-smartphone.htm cellulare smartphone] [http://primonona.info/content/view/love-is/ love is killing me] [http://wedner.info/content/view/gianni-cerquetti.htm gianni cerquetti] [http://klohy.info/img/styles/benq-c.htm benq c51] [http://budget7i.info/lib/scheda-video/ scheda video ati 9550 sapphire] [http://xionny.cn/topic/provincia-di/ provincia di udine] [http://svike.info/view/new/globe.htm globe] [http://primonona.info/content/view/sexy-arab/ sexy arab] [http://svike.info/view/new/life-game.htm life game] [http://manoke.cn/topic/due-giugno/ due giugno festa della repubblica] [http://polex.com.cn/resources/articles/comitato-regionale.htm comitato regionale emilia romagna lnd bo] [http://sneck.info/data/screensaver-moto/ screensaver moto gp] [http://polex.com.cn/resources/articles/federica.htm federica] [http://polex.com.cn/resources/articles/max.htm max 2] [http://manoke.cn/topic/www-penetrazione/ www penetrazione com] [http://primonona.info/content/view/il-segreto/ il segreto del bosco] [http://joperan.org/data/keyword/ keyword] [http://polex.com.cn/resources/articles/tom-gps.htm tom gps mobile] [http://budget7i.info/lib/arredamento-estetica/ arredamento estetica] [http://budget7i.info/lib/michel-bouble/ michel bouble] [http://polex.com.cn/resources/articles/trombia.htm trombia] [http://svike.info/view/new/domini-impianti.htm domini impianti snc] [http://svike.info/view/new/bears-gay.htm bears gay] [http://soler.net.cn/data/asus-geforce.htm asus geforce n6600] [http://funkall.us/images/small/billiards-bombs/ billiards bombs] [http://veggis.org.cn/resources/articles/fear-factor.htm fear factor] [http://manoke.cn/topic/masterizzatori-dvd/ masterizzatori dvd per nb] [http://svike.info/view/new/onda-d.htm onda d urto] [http://funkall.us/images/small/www-frau/ www frau it] [http://veggis.org.cn/resources/articles/dvdr-for.htm dvd-r for authoring 4 7gb] [http://joperan.org/data/vl-zs/ vl z500s] [http://budget7i.info/lib/kurt-angle/ kurt angle] [http://soler.net.cn/data/dx-kodak.htm dx6440 kodak] [http://joperan.org/data/officejet-all/ officejet all in one] [http://polex.com.cn/resources/articles/immergas.htm immergas] [http://xionny.cn/topic/testo-canzone/ testo canzone this love dei maroon5] [http://svike.info/view/new/that-amore.htm that amore] [http://manoke.cn/topic/legge-tognoli/ legge tognoli normativa] [http://funkall.us/images/small/accessori-bambini/ accessori bambini] [http://sneck.info/data/jvc-car/ jvc car audio] [http://joperan.org/data/gi-elle/ gi elle] [http://veggis.org.cn/resources/articles/packard-bell.htm packard bell audiokey] [http://xionny.cn/topic/navi-per/ navi per la sardegna] [http://wedner.info/content/view/is-it.htm is it coz] [http://budget7i.info/lib/testi-gianni/ testi gianni morandi canzone solo chi si] [http://veggis.org.cn/resources/articles/hp-nc.htm hp nc4200] [http://klohy.info/img/styles/logitech-.htm logitech - rally vibration feedback] [http://polex.com.cn/resources/articles/nokia-dcv.htm nokia dcv 14] [http://polex.com.cn/resources/articles/www-escort.htm www escort abruzzo it] {{task}}
{{task}}
Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed in the most natural way possible. Write some element of that array, and then oputput that element. Finally destroy the array if not done by the language itself.
Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed in the most natural way possible. Write some element of that array, and then oputput that element. Finally destroy the array if not done by the language itself.


Line 27: Line 27:




==[[C plus plus|C++]]==
==[[C plus plus|C ]]==
[[Category:C plus plus]]
[[Category:C plus plus]]
With language built-in facilities:
With language built-in facilities:
Line 44: Line 44:
double* array_data = new double[dim1*dim2];
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
for (int i = 0; i < dim1; i)
array[i] = array_data + dim2*i;
array[i] = array_data dim2*i;
// write element
// write element
Line 115: Line 115:
: cell-matrix
: cell-matrix
create ( width height "name" ) over , * cells allot
create ( width height "name" ) over , * cells allot
does> ( x y -- addr ) dup cell+ >r @ * + cells r> + ;
does> ( x y -- addr ) dup cell >r @ * cells r> ;
5 5 cell-matrix test
5 5 cell-matrix test
Line 137: Line 137:
Double[][] array = new Double[nbr1][nbr2];
Double[][] array = new Double[nbr1][nbr2];
array[0][0] = 42.0;
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
System.out.println("The number at place [0 0] is " array[0][0]);
} catch(IOException e) { }
} catch(IOException e) { }
Line 152: Line 152:
sub make_array($ $){
sub make_array($ $){
# get array sizes from provided params, but force numeric value
# get array sizes from provided params, but force numeric value
my $x = ($_[0] =~ /^\d+$/) ? shift : 0;
my $x = ($_[0] =~ /^\d $/) ? shift : 0;
my $y = ($_[0] =~ /^\d+$/) ? shift : 0;
my $y = ($_[0] =~ /^\d $/) ? shift : 0;
# define array, then add multi-dimensional elements
# define array, then add multi-dimensional elements

Revision as of 00:15, 28 August 2007

nvidia gf 6200 128mb the moon italian version philips webcam toucam monitor sony 15 kan kun masterizzatore dvd pioneer feroza daihatsu volvo s40 argento lg dvd home teatre www republica tv color lcd 30 samsung miniket vp estadio w phil ochs forni a microonde con grill lezioni di impianti tecnici vol 2 il soldino birago resurrectio cd kenwood online dating ads la casa tra le stelle. i segreti della nuova stazione spaziale. la macchina del... foto di donne con polpacci grandi lexmark toner x215 fonderia crespi falafel foto baby h fax brother 8070p ti c ha mai mandato linea effe snc carmen villani racconti erotici di zie summit calendario veline semolei www termae info hp laser 1160 funkee green dogs volo mont saint michel aspirapolvere lavor zeus honduras oakley a wire 2 0 yamaha ns-c515 www imprenditoria femminile it suse peluche calcio ps2 videogiochi gang bang turner vegas 1200 il capo regala un sistema audio professionale samsung denon pma-655r ricoh 4000 plotter hp designjet a1 ottimo avvio di gran turismo 3 in italia fz 30 bowlinng trevi tv alta marea a mezzogiorno la fine di troia nel racconto di enea mp3 u2 renaultsport wangan hip hop collection dernier danse guardami film rebel moves bandare foto annuncio amatoriale n.i.c.e. 2 sms win tucano neonato e va albert sordi john jeans duncan james e keedie i believe my heart candida testo della canzone the reason calvignasco enne je t aime ma non plus anima dvd apprendere in rete dragostea din tei di palm phone lenny kravitz calling all angel don giovanni di mozart sagre ciliegia pelicula titanic dissipatori memorie donkie kong calenda maia calendario delle casalinghe pioneer 50 ipod diffusori concessionaria rover morwa ultimi video di spears www italeri com target moda reinas del mediodia mp3 messicani da scaricare beegees staying alive mp3 bratz babyz smash court tennis i miei sei forzati mesenzana stradario italia dragoball z bambola hard bozen llanos testo scusami d alessio gellner libri behringer guitar pack pettorano captain america he shape of my hear ram a fiat marea km 0 e casa frigorifero style soluzioni e trucchi sorrisa toyota avensis sw basso yamaha nhun audi a3 toscana foto di ragazze nude cameron dias programma windows media playar flinta il duomo assicurazioni gps vista weekend lunghi al mare telefax segreteria x-cleaner breezin neffa come mai scott speedman italia sardegna vacanze in videogiochi pc yu gi ho dka tylko ty kochanie teach you childres ww virginio it tutta dance 11 varadero 1000 il terribile ispettore hauptmann, gerhart index2 tumino giovanni i termini piu ricercati x800 agp 256 ogrish ibiza 1999 seat cellulare smartphone love is killing me gianni cerquetti benq c51 scheda video ati 9550 sapphire provincia di udine globe sexy arab life game due giugno festa della repubblica comitato regionale emilia romagna lnd bo screensaver moto gp federica max 2 www penetrazione com il segreto del bosco keyword tom gps mobile arredamento estetica michel bouble trombia domini impianti snc bears gay asus geforce n6600 billiards bombs fear factor masterizzatori dvd per nb onda d urto www frau it dvd-r for authoring 4 7gb vl z500s kurt angle dx6440 kodak officejet all in one immergas testo canzone this love dei maroon5 that amore legge tognoli normativa accessori bambini jvc car audio gi elle packard bell audiokey navi per la sardegna is it coz testi gianni morandi canzone solo chi si hp nc4200 logitech - rally vibration feedback nokia dcv 14 www escort abruzzo it

Task
Create a two-dimensional array at runtime
You are encouraged to solve this task according to the task description, using any language you may know.

Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed in the most natural way possible. Write some element of that array, and then oputput that element. Finally destroy the array if not done by the language itself.

Ada

with Ada.Text_Io; use Ada.Text_Io;
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;

procedure Two_Dimensional_Arrays is
   type Matrix_Type is array(Positive range <>, Positive range <>) of Float;
   Dim_1 : Positive;
   Dim_2 : Positive;
begin
   Get(Item => Dim_1);
   Get(Item => Dim_2);
   -- Create an inner block with the correctly sized array
   declare
      Matrix : Matrix_Type(1..Dim_1, 1..Dim_2);
   begin
      Matrix(1, Dim_2) := 3.14159;
      Put(Item => Matrix(1, Dim_2), Fore => 1, Aft => 5, Exp => 0);
      New_Line;
   end;
   -- The variable Matrix is popped off the stack automatically
end Two_Dimensional_Arrays;


C

With language built-in facilities:

#include <iostream>
#include <istream>
#include <ostream>

int main()
{
  // read values
  int dim1, dim2;
  std::cin >> dim1 >> dim2;

  // create array
  double* array_data = new double[dim1*dim2];
  double** array = new double*[dim1];
  for (int i = 0; i < dim1;   i)
    array[i] = array_data   dim2*i;

  // write element
  array[0][0] = 3.5;

  // output element
  std::cout << array[0][0] << std::endl;

  // get rid of array
  delete[] array;
  delete[] array_data;
}

Using std::vector from the standard library:

#include <iostream>
#include <istream>
#include <ostream>
#include <vector>

int main()
{
  // read values
  int dim1, dim2;
  std::cin >> dim1 >> dim2;

  // create array
  std::vector<std::vector<double> > array(dim1, std::vector<double>(dim2));

  // write element
  array[0][0] = 3.5;

  // output element
  std::cout << array[0][0] << std::endl;

  // the array is automatically freed at the end of main()
}

Clean

import StdEnv

Start :: *World -> { {Real} }
Start world
    # (console, world) = stdio world
      (_, dim1, console) = freadi console
      (_, dim2, console) = freadi console
    = createArray dim1 (createArray dim2 1.0)

Common Lisp

(let ((d1 (read))
      (d2 (read)))
  (assert (and (typep d1 '(integer 1)) 
               (typep d2 '(integer 1))) 
          (d1 d2))
  (let ((array (make-array (list d1 d2) :initial-element nil))
        (p1 0)
        (p2 (floor d2 2)))
    (setf (aref array p1 p2) t)
    (print (aref array p1 p2))))

The assert will allow the user to reenter the dimensions if they are not positive integers.

Forth

: cell-matrix
  create ( width height "name" ) over ,  * cells allot
  does> ( x y -- addr ) dup cell  >r  @ *   cells r>   ;

5 5 cell-matrix test

36 0 0 test !
0 0 test @ .  \ 36

Java

import java.io.*;

public class twoDimArray {
  public static void main(String[] args) {
     try {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        
        int nbr1 = Integer.parseInt(in.readLine());
        int nbr2 = Integer.parseInt(in.readLine());
        
        Double[][] array = new Double[nbr1][nbr2];
        array[0][0] = 42.0;
        System.out.println("The number at place [0 0] is "   array[0][0]);
        
     } catch(IOException e) { }
  }
} 


Perl

Interpreter: Perl 5.x

Predefining an array (or multi-dimension array) size is unnecessary, Perl dynamically resizes the array to meet the requirements. Of course I'm assuming that the user is entering array size 0 based.

sub make_array($ $){
  # get array sizes from provided params, but force numeric value
  my $x = ($_[0] =~ /^\d $/) ? shift : 0;
  my $y = ($_[0] =~ /^\d $/) ? shift : 0;
  
  # define array, then add multi-dimensional elements
  my @array;
  $array[0][0] = 'X '; # first by first element
  $array[5][7] = 'X ' if (5 <= $y and 7 <= $x); # sixth by eighth element, if the max size is big enough
  $array[12][15] = 'X ' if (12 <= $y and 15 <= $x); # thirteeth by sixteenth element, if the max size is big enough
  
  # loop through the elements expected to exist base on input, and display the elements contents in a grid
  foreach my $dy (0 .. $y){
    foreach my $dx (0 .. $x){
      (defined $array[$dy][$dx]) ? (print $array[$dy][$dx]) : (print '. ');
    }
    print "\n";
  }
}

Pop11

vars itemrep;
incharitem(charin) -> itemrep;
;;; Read sizes
vars n1 = itemrep(), n2= itemrep();
;;; Create 0 based array
vars ar = newarray([0 ^(n1 - 1) 0 ^(n2 - 1)], 0);
;;; Set element value
15 -> ar(0, 0);
;;; Print element value
ar(0,0) =>
;;; Make sure array is unreferenced
0 -> ar;

Pop11 is garbage colleted so there is no need to destroy array. However, the array is live as long as variable ar references it. The last assignment makes sure that we loose all our references to the array turning it into garbage.

Pop11 arrays may have arbitrary lower bounds, since we are given only size we create 0 based array.

Python

Interpreter: Python 2.5

 width = int(raw_input("Width of array: "))
 height = int(raw_input("Height of Array: "))
 array = [[0] * width for i in range(height)]
 array[0][0] = 3.5

Note: Some people may instinctively try to write array as [[0] * with] * height, but the * operator creates n references to [[0] * width]

IDL

The following is only for demonstration. No real program should just assume that the user input is valid, integer, large enough etc.

read, x, prompt='Enter x size:'
read, y, prompt='Enter y size:'
d = fltarr(x,y) 

d[3,4] = 5.6
print,d[3,4]
;==> outputs  5.6

delvar, d

Toka

Toka has no direct support for 2D arrays, but they can be created and operated on in a manner similar to normal arrays using the following functions.

[ ( x y -- address )
  cells malloc >r
  dup cells >r
  [ r> r> r> 2dup >r >r swap malloc swap i swap array.put >r ] iterate
r> r> nip
] is 2D-array

[ ( a b address -- value )
  array.get array.get
] is 2D-get-element

[ ( value a b address -- )
  array.get array.put
] is 2D-put-element

And a short test:

5 5 2D-array >r             #! Create an array and save the pointer to it
10 2 3 r@ 2D-put-element    #! Set element 2,3 to 10
2 3 r@ 2D-get-element       #! Get the element at 2,3
r> drop                     #! Discard the pointer to the array