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

m
(add task to aarch64 assembly raspberry pi)
m (→‎{{header|S-BASIC}}: added comment)
 
(18 intermediate revisions by 10 users not shown)
Line 495:
print (array[1,1])
)</syntaxhighlight>
 
=={{header|ALGOL-M}}==
<syntaxhighlight lang="ALGOL">
begin
 
integer first, second;
 
write("Two Dimensional Array Exercise");
write("Length of first dimension:");
read(first);
write("Length of second dimension:");
read(second);
 
begin % we need to start a new block %
integer array test[1:first, 1:second];
test[1,1] := 99;
write("Stored value at 1,1 =",test[1,1]);
end; % array is now out of scope %
 
end
</syntaxhighlight>
{{out}}
<pre>
Two Dimensional Array Exercise
Length of first dimension:
->6
Length of second dimension:
->7
Stored value at 1,1 = 99
</pre>
 
 
=={{header|ALGOL W}}==
Line 860 ⟶ 891:
 
=={{header|BASIC}}==
 
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="applesoftbasic">10 INPUT "ENTER TWO INTEGERS:"; X%, Y%
Line 878 ⟶ 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 896 ⟶ 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 1,627 ⟶ 1,707:
Column 08 = 10 rows
Column 09 = 02 rows</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
write "Number of rows: "
nrows = number input
print nrows
write "Number of columns: "
ncols = number input
print ncols
#
len a[][] nrows
for i to nrows
len a[i][] ncols
.
a[1][1] = 11
print a[1][1]
len a[][] 0
</syntaxhighlight>
 
=={{header|Elena}}==
ELENA 56.0x :
 
Typified array
Line 1,639 ⟶ 1,737:
var m := new Integer();
console.write:("Enter two space delimited integers:");
console.loadLine(n,m);
Line 1,657 ⟶ 1,755:
auto m := new Integer();
console.write:("Enter two space delimited integers:");
console.loadLine(n,m);
auto myArray2 := new object[][](n.Value).populate::(int i => (new object[](m.Value)) );
myArray2[0][0] := 2;
myArray2[1][0] := "Hello";
Line 1,844 ⟶ 1,942:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Create_a_two-dimensional_array_at_runtime}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Create a two-dimensional array at runtime 01.png]]
In '''[https://formulae.org/?example=Create_a_two-dimensional_array_at_runtime this]''' page you can see the program(s) related to this task and their results.
 
[[File:Fōrmulæ - Create a two-dimensional array at runtime 02.png]]
 
There is no need to "release" the array, once the result is delivered, all intermediate elements are destroyed.
 
=={{header|Frink}}==
Line 1,857 ⟶ 1,959:
println[a@(rows-1)@(cols-1)]
</syntaxhighlight>
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
CFStringRef iStr, jStr
long i, j
 
iStr = input @"Enter one positive integer: "
jStr = input @"Enter other positive integer: "
i = fn StringIntegerValue(iStr)
j = fn StringIntegerValue(jStr)
mda (0, 0) = {i, j}
mda (i, j) = i * j
printf @"mda(%ld, %ld) = %ld", i, j, mda_integer (i, j)
 
HandleEvents
</syntaxhighlight>
{{output}}
With inputs of 5 and 7:
<pre>
mda(5, 7) = 35
</pre>
 
=={{header|GAP}}==
Line 2,334 ⟶ 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,794 ⟶ 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,035 ⟶ 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,059 ⟶ 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}}==
Line 3,555 ⟶ 3,711:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin, Stdout
 
var x
16

edits