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

From Rosetta Code
Content added Content deleted
mNo edit summary
Line 1: Line 1:
[http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30318 cheap diethylpropion] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=209 xenical online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30260 cheap clonazepam] [http://library.cshl.edu/wp/vb/member.php?u=1368 nokia ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a19 mp3 ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=225 free kyocera ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=195 rivotril online] [http://students.hsc.unt.edu/housing/item.cfm?type=2865 paxil online] [http://students.hsc.unt.edu/housing/item.cfm?type=2873 nexium online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=114 pharmacy online online] [http://wc1.worldcrossing.com/WebX/.1de609df cheap ambien] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=338 fioricet] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30262 paxil online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=173 free cool ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=178 buy nexium] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=147 cheap zoloft] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=235 tenuate] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30365 mtv ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=342 order diazepam] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30323 flexeril online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=122 rivotril online] [http://students.hsc.unt.edu/housing/item.cfm?type=2913 sonyericsson ringtones] [http://wc1.worldcrossing.com/WebX/.1de609ed buy hoodia] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=119 punk ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=196 motorola ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30278 cheap nexium] [http://wc1.worldcrossing.com/WebX/.1de60a36 zyban online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=127 soma online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30277 cyclobenzaprine online] [http://wc1.worldcrossing.com/WebX/.1de60a30 cheap xenical] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=109 nextel ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30243 cheap ultram] [http://wc1.worldcrossing.com/WebX/.1de609e1 cheap carisoprodol] [http://library.cshl.edu/wp/vb/member.php?u=1376 free motorola ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=198 mtv ringtones] [http://wc1.worldcrossing.com/WebX/.1de609dd alltel ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2921 wwe ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=75 celexa online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=215 buy zoloft] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=175 diazepam online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=236 free tracfone ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2908 free music ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30314 pharmacy online online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=161 viagra online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=170 cheap hydrocodone] [http://news.engin.brown.edu/forums/thread-view.asp?tid=164 norco online] [http://wc1.worldcrossing.com/WebX/.1de60a35 verizon ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=336 carisoprodol online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=70 alltel ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=207 xanax online] [http://wc1.worldcrossing.com/WebX/.1de60a28 cheap soma] [http://wc1.worldcrossing.com/WebX/.1de60a24 propecia online] [http://wc1.worldcrossing.com/WebX/.1de60a21 buy paxil] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30320 cheap rivotril] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30324 online hoodia] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30352 sony ericsson ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2894 flexeril online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30266 lorazepam online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=166 alprazolam online] [http://library.cshl.edu/wp/vb/member.php?u=1343 cheap carisoprodol] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=120 free qwest ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a06 tenuate online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=192 lortab online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=95 kyocera ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=181 cheap sildenafil] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=140 vicodin online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=71 alprazolam online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=125 sharp ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2917 free punk ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=192 but vigrx] [http://wc1.worldcrossing.com/WebX/.1de609f2 meridia online] [http://library.cshl.edu/wp/vb/member.php?u=1374 qwest ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=205 free nextel ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=81 cyclobenzaprine online] [http://wc1.worldcrossing.com/WebX/.1de60a14 jazz ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30327 buy zyban] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30245 online cialis] [http://students.hsc.unt.edu/housing/item.cfm?type=2855 diazepam online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=194 diethylpropion online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=187 kyocera ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30317 zanaflex online] [http://library.cshl.edu/wp/vb/member.php?u=1345 cheap ultram] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30265 order ambien] [http://library.cshl.edu/wp/vb/member.php?u=1372 mp3 ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=107 free music ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=185 cheap zoloft] [http://wc1.worldcrossing.com/WebX/.1de609f1 lortab online] [http://wc1.worldcrossing.com/WebX/.1de60a2e cheap xanax] [http://wc1.worldcrossing.com/WebX/.1de60a0b cheap vigrx] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30297 cheap albuterol] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30361 free kyocera ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=103 free mono ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=97 cheap lipitor] [http://library.cshl.edu/wp/vb/member.php?u=1366 buy propecia] [http://news.engin.brown.edu/forums/thread-view.asp?tid=155 buy xanax] [http://news.engin.brown.edu/forums/thread-view.asp?tid=177 propecia online] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=85 free ericsson ringtones] [http://wc1.worldcrossing.com/WebX/.1de609fb ortho online] [http://wc1.worldcrossing.com/WebX/.1de609ec buy hgh] [http://library.cshl.edu/wp/vb/member.php?u=1370 tracfone ringtones] [http://wc1.worldcrossing.com/WebX/.1de609e3 clomid online] [http://wc1.worldcrossing.com/WebX/.1de60a29 buy tramadol] [http://students.hsc.unt.edu/housing/item.cfm?type=2889 cheap vigrx] [http://wc1.worldcrossing.com/WebX/.1de60a18 free motorola ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=121 free real ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=162 meridia online] [http://students.hsc.unt.edu/housing/item.cfm?type=2886 ortho online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=213 polyphonic ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=135 ultracet online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30335 nextel ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2881 lisinopril online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=241 free sony ericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=128 sony ericsson ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2916 alltel ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2897 free nokia ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a0f cheap cialis] [http://wc1.worldcrossing.com/WebX/.1de60a09 cheap viagra] [http://news.engin.brown.edu/forums/thread-view.asp?tid=207 real ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a0e cheap celexa] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=229 valium online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=354 free nokia ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2866 levitra online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=200 free nokia ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=200 nexium] [http://news.engin.brown.edu/forums/thread-view.asp?tid=214 free cingular ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2910 polyphonic ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2891 diethylpropion online] [http://students.hsc.unt.edu/housing/item.cfm?type=2885 tenuate online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=159 cheap cialis] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30366 free jazz ringtones] [http://wc1.worldcrossing.com/WebX/.1de609fa free online pharmacy] [http://wc1.worldcrossing.com/WebX/.1de60a22 phentermine] [http://news.engin.brown.edu/forums/thread-view.asp?tid=208 free motorola ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1357 levitra online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=195 mono ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=199 zyban online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=363 free samsung ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2901 mp3 ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30235 cheap soma] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=136 cheap ultram] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=72 cheap ambien] [http://students.hsc.unt.edu/housing/item.cfm?type=2862 vicodin online] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30258 vicodin online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=182 funny ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2890 zanaflex] [http://wc1.worldcrossing.com/WebX/.1de609dc buy albuterol] [http://wc1.worldcrossing.com/WebX/.1de60a20 nexium online] [http://students.hsc.unt.edu/housing/item.cfm?type=2875 propecia online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=165 but ambien] [http://wc1.worldcrossing.com/WebX/.1de609f8 free nokia ringtones] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=350 online alprazolam] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=139 cheap viagra] [http://students.hsc.unt.edu/housing/item.cfm?type=2874 cheap ultracet] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=91 hoodia online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=175 cheap cyclobenzaprine] [http://news.engin.brown.edu/forums/thread-view.asp?tid=201 free ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=153 cheap phentermine] [http://students.hsc.unt.edu/housing/item.cfm?type=2848 cheap soma] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30337 real ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=94 jazz ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a0a online vicodin] [http://students.hsc.unt.edu/housing/item.cfm?type=2896 zyban online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=178 ericsson ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a01 free sagem ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1346 diazepam online] [http://news.engin.brown.edu/forums/thread-view.asp?tid=222 free sharp ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a1d cingular ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30230 but adipex] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=138 free verizon ringtones] [http://wc1.worldcrossing.com/WebX/.1de609fe free qwest ringtones] [http://wc1.worldcrossing.com/WebX/.1de609e4 clonazepam online] [http://wc1.worldcrossing.com/WebX/.1de60a31 buy zanaflex] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=106 mtv ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a1a free mtv ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a15 free kyocera ringtones] [http://news.engin.brown.edu/forums/thread-view.asp?tid=218 sony ericsson ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=132 cheap tenuate] [http://students.hsc.unt.edu/housing/item.cfm?type=2904 real ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=137 cheap valium] [http://news.engin.brown.edu/forums/thread-view.asp?tid=168 paxil online] [http://library.cshl.edu/wp/vb/member.php?u=1367 cheap didrex] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30295 sildenafil online] [http://wc1.worldcrossing.com/WebX/.1de609f7 free nextel ringtones] [http://wc1.worldcrossing.com/WebX/.1de609f3 free midi ringtones] [http://library.cshl.edu/wp/vb/member.php?u=1348 cheap ativan] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=337 xanax online] [http://wc1.worldcrossing.com/WebX/.1de609e6 buy cyclobenzaprine] [http://library.cshl.edu/wp/vb/member.php?u=1360 cheap lorazepam] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=162 alltel ringtones] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=176 cheap didrex] [http://news.engin.brown.edu/forums/thread-view.asp?tid=204 mp3 ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2911 cingular ringtones] [http://wc1.worldcrossing.com/WebX/.1de60a07 tracfone ringtones] [http://www.e.kth.se/cgi-bin/esekt/discussion?command=read&discussionid=4&id=30241 xanax online] [http://www.psfc.mit.edu/~jinseok/bbse/view.php?id=presentations&no=356 free tracfone ringtones] [http://www.ees.ufl.edu/alumni/forums.asp?ForumId=5&TopicId=111 norco online] [http://wc1.worldcrossing.com/WebX/.1de60a13 fioricet online] [http://itcweb.ecsu.edu/portal/forums.asp?ForumId=13&TopicId=191 cheap lorazepam] [http://library.cshl.edu/wp/vb/member.php?u=1369 free ringtones] [http://students.hsc.unt.edu/housing/item.cfm?type=2858 viagra online] {{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 13:57, 14 July 2007

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

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