我需要创建一些处理任意大小矩阵的函数.我熟悉这里使用的declare语法,但这是为了大学任务,我的教授告诉我,使用'declare'有一些矫枉过正.我在网上找不到任何相关内容,有什么帮助吗?
基本上我想通过键盘获得矩阵大小,然后使用生成的矩阵,我坚持declare
目前我有:
type myMatrix is array (Natural range <>, Natural range <>) of Integer;
type myVector is array (Natural range <>) of Integer;
Run Code Online (Sandbox Code Playgroud)
我用它作为:
procedure Lab1 is
begin
declare A, B: myVector(1..5):=
(3, 14, 15, 92, 6);
Run Code Online (Sandbox Code Playgroud)
它不允许在运行时指定大小,并且:
declare
int1:Integer:=generate_random_number(50)+2;
int3:Integer:=generate_random_number(50)+2; -- +2 so we don't get length/size 0 or 1
X, Y:myVector(1..int1):=(others=>generate_random_number(20));
MT:myMatrix(1..int1, 1..int3):=(others =>(others=>generate_random_number(10))); -- 'others' used for all the unmentioned elements, http://rosettacode.org/wiki/Array_Initialization
MS:myMatrix(1..int3, 1..int1):=(others =>(others=>generate_random_number(10)));
F3_result:myMatrix(1..int1, 1..int1);
begin
F3_result:=F3(X, Y, MT, …Run Code Online (Sandbox Code Playgroud)