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

m
(Added Easylang)
m (→‎{{header|S-BASIC}}: added comment)
 
(7 intermediate revisions by 4 users not shown)
Line 891:
 
=={{header|BASIC}}==
 
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="applesoftbasic">10 INPUT "ENTER TWO INTEGERS:"; X%, Y%
Line 909 ⟶ 908:
print "a("; string(i); ","; string(j); ") = "; a[i, j]
end</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="vbnet">10 input "Enter two positive integers, separated by a comma? ";i,j
20 dim array(i,j)
30 array(i,j) = i*j
40 print "a(";str$(i);",";str$(j);") = ";array(i,j)
50 erase array</syntaxhighlight>
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
{{works with|QBasic}}
{{works with|MSX BASIC}}
<syntaxhighlight lang="qbasic">10 INPUT "Enter two positive integers, separated by a comma"; I, J
20 DIM ARRAY(I, J)
30 ARRAY(I, J) = I * J
40 PRINT "a("; STR$(I); ","; STR$(J); " ) ="; ARRAY(I, J)
50 ERASE ARRAY</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
<syntaxhighlight lang="qbasic">10 PRINT "ENTER ONE POSITIVE INTEGER: "
20 INPUT I
30 PRINT "ENTER OTHER POSITIVE INTEGER: "
40 INPUT J
50 LET A(I,J) = I*J
60 PRINT "A(";I;",";J;") = ";A(I,J)
70 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
{{works with|GW-BASIC}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|QBasic}}===
Line 927 ⟶ 959:
MAT REDIM array(0,0)
END</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "Create a two-dimensional array at runtime"
VERSION "0.0001"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
i$ = INLINE$("Enter one positive integer: ")
j$ = INLINE$("Enter other positive integer: ")
i = SSHORT(i$)
j = SSHORT(j$)
DIM a[i, j]
a[i, j] = i * j
PRINT "a("; STRING(i); ", "; STRING(j); ") ="; a[i, j]
END FUNCTION</syntaxhighlight>
 
==={{header|Yabasic}}===
Line 2,409 ⟶ 2,458:
=={{header|Objeck}}==
<syntaxhighlight lang="objeck">
class TwoDimArray {
use IO;
function : Main(args : String[]) ~ Nil {
 
rows := Standard->ReadLine()->ToInt();
bundle Default {
cols := Standard->ReadLine()->ToInt();
class TwoDee {
function : Main(args : System.String[]) ~ Nil {
if(rows > DoIt(0 & cols > 0); {
array := Float->New[rows, cols];
}
array[0,0] := 42.0;
Standard->Print("The number at place [0,] is: ")->PrintLine(array[0,0]);
function : native : DoIt() ~ Nil {
Console->GetInstance()->Print("Enter x: ");
x := Console->GetInstance()->ReadString()->ToInt();
Console->GetInstance()->Print("Enter y: ");
y := Console->GetInstance()->ReadString()->ToInt();
if(x > 0 & y > 0) {
array : Int[,] := Int->New[x, y];
array[0, 0] := 2;
array[0, 0]->PrintLine();
};
}
}
Line 2,869 ⟶ 2,907:
33
</pre>
 
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<syntaxhighlight lang="prolog">:- dynamic array/2.
 
run :-
write('Enter two positive integers, separated by a comma: '),
read((I,J)),
assert(array(I,J)),
Value is I * J,
format('a(~w,~w) = ~w', [I, J, Value]),
retractall(array(_,_)).</syntaxhighlight>
 
=={{header|Python}}==
Line 3,110 ⟶ 3,160:
aList[1][2] = 10 See aList[1][2] + nl
</syntaxhighlight>
 
 
« "# rows?" "3" INPUT "# columns?" "5" INPUT <span style="color:grey">''@ ask for size, with 3 and 5 as default values''</span>
2 →LIST STR→ 0 CON <span style="color:grey">''@ create array in stack''</span>
{ 1 2 } TIME PUT <span style="color:grey">''@ put current time at array[1,2] ''</span>
{ 1 2 } GET <span style="color:grey">''@ read array[1,2] and remove array from the stack ''</span>
» '<span style="color:blue">TASK' STO</span>
 
=={{header|Ruby}}==
Line 3,134 ⟶ 3,191:
println!("{}", v[0][0]);
}</syntaxhighlight>
 
=={{header|S-BASIC}}==
<syntaxhighlight lang="BASIC">
var a, b = integer
 
print "Two-Dimensional Array Example"
input "Size of first dimension"; a
input "Size of second dimension"; b
 
dim integer test_array(a, b)
 
test_array(1,1) = 99 rem S-BASIC arrays are indexed from 1
 
print "Value stored at 1,1 ="; test_array(1,1)
 
end
</syntaxhighlight>
{{out}}
<pre>
Two-Dimensional Array Example
Size of first dimension? 7
Size of second dimension? 7
Value stored at 1,1 = 99
</pre>
 
=={{header|Scala}}==
13

edits