RosettaCodeData/Task/Create-a-two-dimensional-array-at-runtime/D/create-a-two-dimensional-array-at-runtime.d

25 lines
533 B
D
Raw Permalink Normal View History

2013-04-10 16:57:12 -07:00
void main() {
2013-10-27 22:24:23 +00:00
import std.stdio, std.conv, std.string;
2013-04-10 16:57:12 -07:00
int nRow, nCol;
write("Give me the numer of rows: ");
try {
2013-10-27 22:24:23 +00:00
nRow = readln.strip.to!int;
} catch (StdioException) {
2013-04-10 16:57:12 -07:00
nRow = 3;
2013-10-27 22:24:23 +00:00
writeln;
2013-04-10 16:57:12 -07:00
}
write("Give me the numer of columns: ");
try {
2013-10-27 22:24:23 +00:00
nCol = readln.strip.to!int;
} catch (StdioException) {
2013-04-10 16:57:12 -07:00
nCol = 5;
2013-10-27 22:24:23 +00:00
writeln;
2013-04-10 16:57:12 -07:00
}
auto array = new float[][](nRow, nCol);
array[0][0] = 3.5;
writeln("The number at place [0, 0] is ", array[0][0]);
}