Anonymous user
Create a two-dimensional array at runtime: Difference between revisions
Create a two-dimensional array at runtime (view source)
Revision as of 15:55, 3 February 2009
, 15 years agono edit summary
(→{{header|Common Lisp}}: Change to tt) |
No edit summary |
||
Line 4:
=={{header|Ada}}==
<lang ada>
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
Line 26:
-- The variable Matrix is popped off the stack automatically
end Two_Dimensional_Arrays;
</
=={{header|ALGOL 68}}==
Line 361:
{{works with|Python| 2.5}}
<lang python> width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in xrange(height)]
myarray[0][0] = 3.5
print myarray[0][0]</
'''Note:''' Some people may instinctively try to write myarray as [[0] * width] * height, but the * operator creates ''n'' references to [[0] * width]
Line 371:
You can also use a two element tuple to index a dictionary like so:
<lang python> myarray = dict(((w,h), 0) for w in range(width) for h in range(height))
myarray[(0,0)] = 3.5
print myarray[(0,0)]</
=={{header|Ruby}}==
|