Hello!

It is necessary to make the parameters for rows and columns entered from the keyboard, and the matrix itself is filled randomly. What is the implementation of the input matrix should be in the procedure. And the output of the matrix to the screen in another procedure.

I do for now to enter the matrix. But not quite work.

Error: "Error 20: Variable identifier expected".

And points to the variable a in the procedure. So I understand that for the variable b will be the same situation.

I think that const needs to be removed, because it is all the same constant, but I need a variable value. But then there is an error in the line

 type mass = array [1..a,1..b] of integer; 

Because a and b not defined.

Tell me, please, what to do. How to write correctly?

I would be very grateful if you write an example :)

That's what happened with me.

 const a=10; b=10; type mass = array [1..a,1..b] of integer; var matr : mass; procedure zapolnenie_matricij; begin var i,j:integer; writeln('Введите параметр для строк: '); readln(a); writeln('Введите параметр для столбцов: '); readln(b); randomize; for i:=1 to a do begin for j:=1 to b do begin matr[i,j]=random(15); end; end; end; 

If I try to write a and b as variables in the procedure, then the error "Error 113: Error in statement" appears.

    4 answers 4

    I would write your program like this:

      Const { здесь ограничимся максимально возможными числами строк и столбцов } a0=20; b0=20; Var Matr: Array[1..a0, 1..b0] Of Integer; a, b: integer; { а здесь зададим переменные } procedure zapolnenie_matricij; var i, j: integer; begin (* тут проверяем попадает ли введённое число а заданную границу *) Repeat write('a = '); readln(a); Until (a In [2..a0]); Repeat write('b = '); readln(b); Until (b In [2..b0]); randomize; (* советую приучаться не писать "лишние" программные скобки begin...end *) for i:=1 to a do for j:=1 to b do matr[i,j]:=random(15); end; Procedure MatrixScreenOut; var i, j: integer; Begin for i:=1 to a do begin for j:=1 to b do Write(matr[i,j]:3); WriteLn; end; End; begin zapolnenie_matricij; MatrixScreenOut; WriteLn('Davi na ENTER!!!'); ReadLn; end. 

    And if you do everything in one procedure, then you can do with one cycle (with nested):

      for i:=1 to a do begin for j:=1 to b do begin matr[i,j]:=random(15); Write(matr[i,j]:3); end; WriteLn; end; 

    In this case, do not have to fill out, and then display the matrix separately.

      In pascal, you cannot initialize variables in the var section. But this is implemented using typed constants, which are not actually constants:

       const a : integer = 10; b : integer = 10; 

      We obtain two variables a and b , despite the const .

      • Thanks for the answer, it turned out to be done as needed. True, everything is in one procedure, but the main thing is working :) - elenavictory

      You need to replace const with var :

       var a,b:integer; 
      • No, then another error appears. "Error 133: Cannot evaluate this expression". - elenavictory

      Hooray! I made the necessary procedure myself! :) In two procedures I failed. But it turned out in one. And, most importantly, it works correctly!

      Here is the result of my work :)

        program zadanie; uses crt; const a = 10; {dlya zadaniya strok matricij} b = 10; {dlya zadaniya stolbcov matricij} type mass = array [1..a, 1..b] of integer; var matr : mass; {dlya matricij} m : integer; {znachenie dlya sravneniya} i,j:integer; {*********************************************************************} procedure matrica_na_ekrane; {procedyra dlya vivoda matricij na ekran} var i,j:integer; a,b:integer; begin writeln('Vvedite a: '); readln(a); writeln('Vvedite b: '); readln(b); randomize; for i:=1 to a do begin for j:=1 to b do begin matr[i,j]:=random(10); end; end; for i:=1 to a do begin for j:=1 to b do begin write(matr[i,j]:5); end; writeln;writeln; end; end; {*********************************************************************} BEGIN clrscr; matrica_na_ekrane; readln; END. 
      • It should be borne in mind that if the user enters a or b> 10, then the output will go beyond the initial array with dimensions of 10x10 (after changing a or b, the dimensions of the array itself do not change automatically). You need to either do the initial a and b more (100 and 100 for example), or allocate memory dynamically (see here for example), or switch to Delphi and use dynamic arrays - insolor