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

From Rosetta Code
Content added Content deleted
(Undo spam)
mNo edit summary
Line 1: Line 1:
[http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=839 kyocera ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/nexium_2418.htm nexium online] [http://wc1.worldcrossing.com/WebX/.1de609f3 midi ringtones] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=827 free cingular ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f7 free nextel ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a20 nexium online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=195 mono ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=77 free cingular ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=85 tenuate online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3734 sony ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30265 ambien online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=170 free cingular ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30332 tracfone ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=53 cheap xenical] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3759 cheap flexeril] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=55 zoloft online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=169 cialis] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=78 buy hoodia] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=213 cheap prozac] [http://students.hsc.unt.edu/housing/item.cfm?type=2849 but valium] [http://students.hsc.unt.edu/housing/item.cfm?type=2880 cheap albuterol] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3717 order hgh] [http://wc1.worldcrossing.com/WebX/.1de60a00 rivotril online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=52 xanax online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/cyclobenzaprine_72.htm cheap cyclobenzaprine] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=175 diazepam online] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=39 cialis online] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=66 flexeril online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30345 sprint ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=96 zyban online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=99 free tracfone ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=32 cheap valium] [http://students.hsc.unt.edu/housing/item.cfm?type=2867 order hydrocodone] [http://students.hsc.unt.edu/housing/item.cfm?type=2872 online cyclobenzaprine] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=222 cheap vigrx] [http://students.hsc.unt.edu/housing/item.cfm?type=2875 propecia online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30320 rivotril online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30253 cheap norco] [http://library.cshl.edu/wp/vb/member.php?u=1369 free free ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3769 free sony ericsson ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2889 cheap vigrx] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=74 free mp3 ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2925 mtv ringtones] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=828 free sagem ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=72 free tracfone ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=96 free sony ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=188 levitra online] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=46 nexium] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=51 ambien] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=82 tracfone ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=40 cheap hydrocodone] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/ambien_7869.htm buy ambien] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3737 but phentermine] [http://library.cshl.edu/wp/vb/member.php?u=1347 but cialis] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=59 ortho online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=837 free midi ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=46 alprazolam online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=83 lipitor online] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=44 buy wellbutrin] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=60 online pharmacy online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30339 free samsung ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3771 cool ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=83 free funny ringtones] [http://wc1.worldcrossing.com/WebX/.1de609dd free alltel ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=26 fioricet online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=97 free nokia ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=205 paxil online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=88 lortab online] [http://wc1.worldcrossing.com/WebX/.1de60a34 sony ericsson ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=211 free polyphonic ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30308 cheap lipitor] [http://students.hsc.unt.edu/housing/item.cfm?type=2886 order ortho] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=80 cool ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=77 cheap prozac] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30321 cheap hgh] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3741 viagra online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=94 jazz ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=126 sildenafil online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30352 sony ericsson ringtones] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=809 hgh online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=112 free sagem ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a12 free ericsson ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30250 viagra online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=134 tramadol online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3742 adipex online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=826 polyphonic ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=69 hgh online] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=35 xanax online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=139 cheap viagra] [http://students.hsc.unt.edu/housing/item.cfm?type=2895 hoodia online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=776 norco] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/alprazolam_413.htm alprazolam online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30248 cheap ativan] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=92 hydrocodone online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=228 ultram online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=767 xanax] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=840 sony ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=92 verizon ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/sonyericsson_2004.htm sony ericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=119 punk ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=214 zanaflex online] [http://library.cshl.edu/wp/vb/member.php?u=1379 music ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=108 music ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a09 viagra online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=67 cheap hydrocodone] [http://wc1.worldcrossing.com/WebX/.1de60a30 cheap xenical] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=836 sharp ringtones] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=76 hgh online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=115 phentermine online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=84 celexa online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=98 free free ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=93 hgh online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=75 celexa online] [http://wc1.worldcrossing.com/WebX/.1de609f8 free nokia ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=105 free motorola ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=240 soma online] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=88 free motorola ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3692 cheap tramadol] [http://library.cshl.edu/wp/vb/member.php?u=1363 buy cyclobenzaprine] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=61 norco online] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=67 cheap celexa] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=81 cyclobenzaprine online] [http://library.cshl.edu/wp/vb/member.php?u=1345 cheap ultram] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=790 propecia online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30309 cheap celexa] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=825 free verizon ringtones] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=70 xenical online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=783 but ambien] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=80 cheap albuterol] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30243 cheap ultram] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=136 ultram online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=762 buy tramadol] [http://library.cshl.edu/wp/vb/member.php?u=1359 ambien online] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=24 carisoprodol online] [http://students.hsc.unt.edu/housing/item.cfm?type=2901 free mp3 ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=203 norco] [http://students.hsc.unt.edu/housing/item.cfm?type=2862 vicodin online] [http://kc.vanderbilt.edu/forums/toast.asp?sub=show&action=posts&fid=5&tid=123 sony ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=67 buy hoodia] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=239 cheap sildenafil] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3743 cheap vicodin] [http://wc1.worldcrossing.com/WebX/.1de60a18 motorola ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2926 free jazz ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2903 free qwest ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a0f cheap cialis] [http://students.hsc.unt.edu/housing/item.cfm?type=2868 cheap ambien] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=64 lisinopril online] [http://students.hsc.unt.edu/housing/item.cfm?type=2909 verizon ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30237 cheap valium] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=37 ultram online] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=774 meridia online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30263 cheap levitra] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/xenical_6681.htm cheap xenical] [http://students.hsc.unt.edu/housing/item.cfm?type=2918 cool ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3755 cheap ortho] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/xanax_4637.htm cheap xanax] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3696 online fioricet] [http://www4.nau.edu/fera/index.asp?sub=show&action=posts&fid=4&tid=36 but fioricet] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3719 nokia ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3712 lipitor online] [http://library.cshl.edu/wp/vb/member.php?u=1386 mono ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a11 buy diethylpropion] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=92 sharp ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=99 jazz ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=84 diethylpropion online] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=23 phentermine online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=185 hydrocodone online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=238 free sharp ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1385 sony ericsson ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=173 free cool ringtones] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=810 order flexeril] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=176 cheap didrex] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30335 free nextel ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2896 buy zyban] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=841 free ericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=91 hoodia online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3720 free tracfone ringtones] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=91 free cool ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=199 free music ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=172 cheap clonazepam] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3750 cheap didrex] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=789 ultracet] [http://ae.siam.edu/forums/toast.asp?sub=show&action=posts&fid=2&tid=57 cheap celexa] [http://wc1.worldcrossing.com/WebX/.1de60a1e flexeril online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/sagemringtones_756.htm free sagem ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2899 free tracfone ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=148 zyban online] [http://students.hsc.unt.edu/housing/item.cfm?type=2888 lortab online] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3749 cheap ultracet] [http://wc1.worldcrossing.com/WebX/.1de609f0 cheap lorazepam] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=15&tid=3753 zoloft] [http://www.aswsu-ddp.wsu.edu/toast/forums.asp?sub=show&action=posts&fid=3&tid=788 buy nexium] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=145 cheap xenical] [http://students.hsc.unt.edu/housing/item.cfm?type=2897 free nokia ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/monoringtones_7654.htm mono ringtones] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/nextelringtones_3485.htm free nextel ringtones] [http://www.ovu.edu/community/toast.asp?sub=show&action=posts&fid=5&tid=3723 motorola ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=192 lortab online] [http://www.colorado.edu/studentgroups/backcountryclub/blahdocs/uploads/diazepam_558.htm cheap diazepam] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=218 qwest ringtones] {{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 21:29, 21 July 2007

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

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

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 put-element >r ] iterate
r> r> nip
] is 2D-array
[ ( a b address -- value )
  get-element get-element
] is 2D-get-element
[ ( value a b address -- )
  get-element put-element
] 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