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

From Rosetta Code
Content added Content deleted
No edit summary
Line 1: Line 1:
[http://dcc.syr.edu/dforum/message.asp?MessageID=49024 adipex online] [http://ccfl.unl.edu/twiki/pub/Main/PaulinePauline/vuxinuz.htm motorola ringtones] [http://bugzilla.internet2.edu/attachment.cgi?id=722 adipex online] [http://www.hollins.edu/ubb/Forum32/HTML/000365.html free nextel ringtones] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=21 ultram online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/PhillipRewers/jusify.htm nokia ringtones] [http://devel.linux.duke.edu/bugzilla/attachment.cgi?id=262 free funny ringtones] [http://dcc.syr.edu/dforum/message.asp?MessageID=48922 carisoprodol online] [http://bugzilla.internet2.edu/attachment.cgi?id=742 buy phentermine] [http://www.hollins.edu/ubb/Forum32/HTML/000283.html valium online] [http://ccfl.unl.edu/twiki/pub/Main/PaulinePauline/jowili.htm free qwest ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000342.html cheap tenuate] [http://bugzilla.internet2.edu/attachment.cgi?id=750 free sonyericsson ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/PhillipRewers/licox.htm motorola ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000319.html cyclobenzaprine online] [http://www.hollins.edu/ubb/Forum32/HTML/000295.html order norco] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/JustinJonson/tokuny.htm lortab online] [http://www.hollins.edu/ubb/Forum32/HTML/000354.html flexeril online] [http://bugzilla.internet2.edu/attachment.cgi?id=752 tracfone ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000285.html cheap carisoprodol] [http://www.hollins.edu/ubb/Forum32/HTML/000299.html online paxil] [http://dcc.syr.edu/dforum/message.asp?MessageID=49063 qwest ringtones] [http://devel.linux.duke.edu/bugzilla/attachment.cgi?id=249 buy tramadol] [http://ccfl.unl.edu/twiki/pub/Main/AlexCarneyham/sywexyc.htm buy levitra] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/RobertSmith/zexuc.htm cheap didrex] [http://www.hollins.edu/ubb/Forum32/HTML/000380.html punk ringtones] [http://ccfl.unl.edu/twiki/pub/Main/AlexCarneyham/kite.htm ultracet] [http://www.hollins.edu/ubb/Forum32/HTML/000311.html buy hydrocodone] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=42 buy xenical] [http://ist.greenville.edu/drupal/files/luho.html nokia ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/SelmaJeremy/rufog.htm free sprint ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/JustinJonson/jujope.htm diethylpropion online] [http://www.hollins.edu/ubb/Forum32/HTML/000294.html adipex online] [http://ccfl.unl.edu/twiki/pub/Main/PaulinePauline/roteryh.htm free polyphonic ringtones] [http://cyrusimap.web.cmu.edu/twiki/bin/view/Main/AndreaHolivel cheap cialis] [http://dcc.syr.edu/dforum/message.asp?MessageID=49016 ultram online] [http://www.hollins.edu/ubb/Forum32/HTML/000336.html clomid online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/SelmaJeremy/hijosij.htm free sagem ringtones] [http://ist.greenville.edu/drupal/files/bigibe.html nextel ringtones] [http://dcc.syr.edu/dforum/message.asp?MessageID=49027 alprazolam online] [http://www.hollins.edu/ubb/Forum32/HTML/000288.html ultram online] [http://ccfl.unl.edu/twiki/pub/Main/AlexCarneyham/hicif.htm alprazolam online] [http://ccfl.unl.edu/twiki/pub/Main/PaulinePauline/sujy.htm free samsung ringtones] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=25 cheap viagra] [http://bugzilla.internet2.edu/attachment.cgi?id=735 motorola ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/AshleighRodriquez/jybuhi.htm cheap viagra] [http://dcc.syr.edu/dforum/message.asp?MessageID=48916 phentermine online] [http://devel.linux.duke.edu/bugzilla/attachment.cgi?id=256 ultram online] [http://bugzilla.internet2.edu/attachment.cgi?id=760 cheap diazepam] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/JustinJonson/xyhyj.htm cheap rivotril] [http://ccfl.unl.edu/twiki/pub/Main/SummersFrank/vuru.htm cheap ativan] [http://ccfl.unl.edu/twiki/pub/Main/AlexCarneyham/hykidi.htm order clonazepam] [http://www.hollins.edu/ubb/Forum32/HTML/000281.html tramadol online] [http://devel.linux.duke.edu/bugzilla/attachment.cgi?id=253 carisoprodol online] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=26 meridia online] [http://ist.greenville.edu/drupal/files/dydyse.html cheap valium] [http://ccfl.unl.edu/twiki/pub/Main/HermanHogg/rukexo.htm cheap zoloft] [http://ist.greenville.edu/drupal/files/kuxer.html cyclobenzaprine online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/SelmaJeremy/cybo.htm free sonyericsson ringtones] [http://ccfl.unl.edu/twiki/pub/Main/MarthaBell/nezyz.htm flexeril online] [http://ccfl.unl.edu/twiki/pub/Main/SummersFrank/lyfogo.htm xanax] [http://ccfl.unl.edu/twiki/pub/Main/MarthaBell/wofo.htm free nokia ringtones] [http://grid.unimelb.edu.au/twiki/pub/Main/JamesMiller/sonuhop.htm valium online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/RobertSmith/pevesuz.htm cheap wellbutrin] [http://ccfl.unl.edu/twiki/pub/Main/HermanHogg/rypel.htm sildenafil] [http://www.hollins.edu/ubb/Forum32/HTML/000339.html order zoloft] [http://devel.linux.duke.edu/bugzilla/attachment.cgi?id=251 cheap valium] [http://www.hollins.edu/ubb/Forum32/HTML/000384.html free midi ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000290.html cialis online] [http://bugzilla.internet2.edu/attachment.cgi?id=744 free qwest ringtones] [http://devel.linux.duke.edu/bugzilla/attachment.cgi?id=266 free real ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/PhillipRewers/kino.htm free real ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/SelmaJeremy/belizyl.htm free polyphonic ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/PhillipRewers/dijuxoj.htm free tracfone ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000322.html cheap ultracet] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=28 norco online] [http://dcc.syr.edu/dforum/message.asp?MessageID=49072 polyphonic ringtones] [http://bugzilla.internet2.edu/attachment.cgi?id=732 buy levitra] [http://ccfl.unl.edu/twiki/pub/Main/AlexCarneyham/woguked.htm ambien online] [http://www.hollins.edu/ubb/Forum32/HTML/000334.html cheap sildenafil] [http://www.hollins.edu/ubb/Forum32/HTML/000333.html prozac online] [http://ist.greenville.edu/drupal/files/rucod.html xanax] [http://www.hollins.edu/ubb/Forum32/HTML/000343.html cheap ortho] [http://ist.greenville.edu/drupal/files/wypy.html funny ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000296.html vicodin online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/BilyKroft/koky.htm phentermine online] [http://bugzilla.internet2.edu/attachment.cgi?id=740 norco online] [http://ccfl.unl.edu/twiki/pub/Main/HermanHogg/figog.htm buy lortab] [http://ccfl.unl.edu/twiki/pub/Main/AlexCarneyham/kozu.htm hydrocodone online] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=24 cheap ativan] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/AshleighRodriquez/godufit.htm buy paxil] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/SelmaJeremy/sevuv.htm mono ringtones] [http://bugzilla.internet2.edu/attachment.cgi?id=755 valium] [http://grid.unimelb.edu.au/twiki/pub/Main/JamesMiller/sicofyr.htm tramadol online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/BettySmith/kuvodoj.htm cheap zoloft] [http://dcc.syr.edu/dforum/message.asp?MessageID=49034 online hydrocodone] [http://dcc.syr.edu/dforum/message.asp?MessageID=49022 cheap viagra] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/BettySmith/niwupu.htm albuterol] [http://ccfl.unl.edu/twiki/pub/Main/MarthaBell/gedenu.htm cheap rivotril] [http://ccfl.unl.edu/twiki/pub/Main/PaulinePauline/dyzoko.htm verizon ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000314.html online lorazepam] [http://grid.unimelb.edu.au/twiki/pub/Main/JackLawson/rejyvob.htm order viagra] [http://www.hollins.edu/ubb/Forum32/HTML/000325.html didrex online] [http://ccfl.unl.edu/twiki/pub/Main/SummersFrank/kuzypuh.htm phentermine online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/SelmaJeremy/nofelyr.htm free cingular ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000389.html ericsson ringtones] [http://dcc.syr.edu/dforum/message.asp?MessageID=49077 sony ericsson ringtones] [http://devel.linux.duke.edu/bugzilla/attachment.cgi?id=267 free motorola ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/JustinJonson/kuluc.htm zanaflex online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/JustinJonson/gekiw.htm flexeril online] [http://www.hollins.edu/ubb/Forum32/HTML/000369.html samsung ringtones] [http://devel.linux.duke.edu/bugzilla/attachment.cgi?id=259 nokia ringtones] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=22 cheap diazepam] [http://www.hollins.edu/ubb/Forum32/HTML/000376.html free sonyericsson ringtones] [http://ist.greenville.edu/drupal/files/devowy.html lorazepam online] [http://ist.greenville.edu/drupal/files/role.html free real ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000351.html but rivotril] [http://www.hollins.edu/ubb/Forum32/HTML/000312.html buy ambien] [http://www.hollins.edu/ubb/Forum32/HTML/000337.html albuterol online] [http://dcc.syr.edu/dforum/message.asp?MessageID=49018 cialis online] [http://dcc.syr.edu/dforum/message.asp?MessageID=49035 ambien online] [http://bugzilla.internet2.edu/attachment.cgi?id=746 sagem ringtones] [http://dcc.syr.edu/dforum/message.asp?MessageID=49025 cheap norco] [http://ist.greenville.edu/drupal/files/puweso.html meridia online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/RobertSmith/cibedis.htm nexium online] [http://ccfl.unl.edu/twiki/pub/Main/PaulinePauline/zivy.htm free mono ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000352.html hgh online] [http://bugzilla.internet2.edu/attachment.cgi?id=754 cheap ultram] [http://ist.greenville.edu/drupal/files/ruwyze.html ativan online] [http://ccfl.unl.edu/twiki/pub/Main/AlexCarneyham/linefej.htm buy wellbutrin] [http://ccfl.unl.edu/twiki/pub/Main/MarthaBell/rofev.htm free free ringtones] [http://ist.greenville.edu/drupal/files/pobiwi.html diazepam online] [http://bugzilla.internet2.edu/attachment.cgi?id=751 free sprint ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000345.html lortab online] [http://grid.unimelb.edu.au/twiki/pub/Main/JamesMiller/bopogo.htm carisoprodol online] [http://dcc.syr.edu/dforum/message.asp?MessageID=49071 verizon ringtones] [http://ccfl.unl.edu/twiki/pub/Main/HermanHogg/relu.htm clomid online] [http://ccfl.unl.edu/twiki/pub/Main/AlexCarneyham/sifus.htm xenical online] [http://bugzilla.internet2.edu/attachment.cgi?id=759 xanax online] [http://www.hollins.edu/ubb/Forum32/HTML/000360.html free free ringtones] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=43 cheap wellbutrin] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=15 carisoprodol online] [http://cyrusimap.web.cmu.edu/twiki/bin/view/Main/DikVolirev tracfone ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/SherylDiu/popuxo.htm free sharp ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000291.html buy ativan] [http://ist.greenville.edu/drupal/files/covubi.html norco online] [http://ccfl.unl.edu/twiki/pub/Main/PaulinePauline/wetule.htm free sony ericsson ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000362.html tracfone ringtones] [http://dcc.syr.edu/dforum/message.asp?MessageID=49075 free sonyericsson ringtones] [http://dcc.syr.edu/dforum/message.asp?MessageID=48901 soma online] [http://www.hollins.edu/ubb/Forum32/HTML/000293.html meridia online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/JustinJonson/gelol.htm buy zyban] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/AshleighRodriquez/rigyse.htm clonazepam] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/SelmaJeremy/kohe.htm free music ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/RobertSmith/pybex.htm cheap cyclobenzaprine] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/AshleighRodriquez/pero.htm cheap ativan] [http://ccfl.unl.edu/twiki/pub/Main/AlexCarneyham/huvixu.htm paxil online] [http://grid.unimelb.edu.au/twiki/pub/Main/JackLawson/nunuso.htm ativan online] [http://dcc.syr.edu/dforum/message.asp?MessageID=49046 but nexium] [http://ccfl.unl.edu/twiki/pub/Main/MarthaBell/cohufyk.htm free mp3 ringtones] [http://ccfl.unl.edu/twiki/pub/Main/MarthaBell/vekorot.htm hgh online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/RobertSmith/kuky.htm propecia online] [http://devel.linux.duke.edu/bugzilla/attachment.cgi?id=268 free samsung ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/BettySmith/kyzefe.htm ortho online] [http://ccfl.unl.edu/twiki/pub/Main/MarthaBell/wydyty.htm zyban] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/SherylDiu/gefu.htm free punk ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000340.html lipitor online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/SherylDiu/ruviti.htm free mtv ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000346.html vigrx online] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=41 cheap lorazepam] [http://cyrusimap.web.cmu.edu/twiki/bin/view/Main/RingoFloper fioricet online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/RobertSmith/tuju.htm lorazepam online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/SherylDiu/sypev.htm cool ringtones] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=30 free qwest ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000289.html cheap diazepam] [http://ccfl.unl.edu/twiki/pub/Main/HermanHogg/kuhufid.htm tenuate online] [http://dcc.syr.edu/dforum/message.asp?MessageID=49028 clonazepam online] [http://dcc.syr.edu/dforum/message.asp?MessageID=49015 fioricet online] [http://bugzilla.internet2.edu/attachment.cgi?id=725 ativan online] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=36 clonazepam online] [http://ccfl.unl.edu/twiki/pub/Main/HermanHogg/zivesup.htm propecia online] [http://dcc.syr.edu/dforum/message.asp?MessageID=49061 free mp3 ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/RobertSmith/donyki.htm hydrocodone online] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/BilyKroft/hywi.htm cheap carisoprodol] [http://dcc.syr.edu/dforum/message.asp?MessageID=49051 cheap didrex] [http://www.hollins.edu/ubb/Forum32/HTML/000300.html levitra] [http://bugzilla.internet2.edu/attachment.cgi?id=738 nextel ringtones] [http://www.hollins.edu/ubb/Forum32/HTML/000356.html zyban online] [http://bugzilla.internet2.edu/attachment.cgi?id=736 free mp3 ringtones] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=38 levitra] [http://www.hollins.edu/ubb/Forum32/HTML/000341.html buy celexa] [http://grid.unimelb.edu.au/twiki/pub/Main/NoriJohn/rupo.htm tracfone ringtones] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=27 adipex online] [http://dcc.syr.edu/dforum/message.asp?MessageID=49056 free free ringtones] [http://ccfl.unl.edu/twiki/pub/Main/PaulinePauline/wypo.htm free music ringtones] [http://www.coe.unt.edu/chec/forum/forum_posts.asp?TID=29 free nextel ringtones] [http://dcc.syr.edu/dforum/message.asp?MessageID=49054 free nokia ringtones] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/AshleighRodriquez/putyh.htm cheap levitra] [http://wwwx.cs.unc.edu/~kmp/twiki40/pub/Main/PhillipRewers/wozone.htm free free ringtones] [http://dcc.syr.edu/dforum/message.asp?MessageID=49049 cheap propecia] {{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 125: Line 125:
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 140: Line 140:
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 20:08, 4 May 2007

adipex online motorola ringtones adipex online free nextel ringtones ultram online nokia ringtones free funny ringtones carisoprodol online buy phentermine valium online free qwest ringtones cheap tenuate free sonyericsson ringtones motorola ringtones cyclobenzaprine online order norco lortab online flexeril online tracfone ringtones cheap carisoprodol online paxil qwest ringtones buy tramadol buy levitra cheap didrex punk ringtones ultracet buy hydrocodone buy xenical nokia ringtones free sprint ringtones diethylpropion online adipex online free polyphonic ringtones cheap cialis ultram online clomid online free sagem ringtones nextel ringtones alprazolam online ultram online alprazolam online free samsung ringtones cheap viagra motorola ringtones cheap viagra phentermine online ultram online cheap diazepam cheap rivotril cheap ativan order clonazepam tramadol online carisoprodol online meridia online cheap valium cheap zoloft cyclobenzaprine online free sonyericsson ringtones flexeril online xanax free nokia ringtones valium online cheap wellbutrin sildenafil order zoloft cheap valium free midi ringtones cialis online free qwest ringtones free real ringtones free real ringtones free polyphonic ringtones free tracfone ringtones cheap ultracet norco online polyphonic ringtones buy levitra ambien online cheap sildenafil prozac online xanax cheap ortho funny ringtones vicodin online phentermine online norco online buy lortab hydrocodone online cheap ativan buy paxil mono ringtones valium tramadol online cheap zoloft online hydrocodone cheap viagra albuterol cheap rivotril verizon ringtones online lorazepam order viagra didrex online phentermine online free cingular ringtones ericsson ringtones sony ericsson ringtones free motorola ringtones zanaflex online flexeril online samsung ringtones nokia ringtones cheap diazepam free sonyericsson ringtones lorazepam online free real ringtones but rivotril buy ambien albuterol online cialis online ambien online sagem ringtones cheap norco meridia online nexium online free mono ringtones hgh online cheap ultram ativan online buy wellbutrin free free ringtones diazepam online free sprint ringtones lortab online carisoprodol online verizon ringtones clomid online xenical online xanax online free free ringtones cheap wellbutrin carisoprodol online tracfone ringtones free sharp ringtones buy ativan norco online free sony ericsson ringtones tracfone ringtones free sonyericsson ringtones soma online meridia online buy zyban clonazepam free music ringtones cheap cyclobenzaprine cheap ativan paxil online ativan online but nexium free mp3 ringtones hgh online propecia online free samsung ringtones ortho online zyban free punk ringtones lipitor online free mtv ringtones vigrx online cheap lorazepam fioricet online lorazepam online cool ringtones free qwest ringtones cheap diazepam tenuate online clonazepam online fioricet online ativan online clonazepam online propecia online free mp3 ringtones hydrocodone online cheap carisoprodol cheap didrex levitra nextel ringtones zyban online free mp3 ringtones levitra buy celexa tracfone ringtones adipex online free free ringtones free music ringtones free nextel ringtones free nokia ringtones cheap levitra free free ringtones cheap propecia

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.

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";
  }
}

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