I have the following task: Determine the number of the column of a rectangular matrix in which the number of elements larger than M is minimal. In this case, you need to enter the parameters of the matrix from the keyboard, and fill it in randomly. Further, in the function you need to implement just the main task of the program - to compare the elements in the column, find how many elements in it are more than the variable M, do the same with other columns and compare finally, where the number of elements greater than M is minimal.
I managed to enter the matrix and output it to the screen, not without the help of users HashCode :) Here you can see if anyone is interested here
Now I wonβt figure out how to make it possible to work with the elements of an array precisely by columns in a function, where exactly their comparison with the variable M by columns will take place.
I think that we need to add a one-dimensional array to which values ββfrom the columns will be copied.
What do you say?
Here is the code that I get. So far, stalled on the function.
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; stolbcij_matricij = array [1..b] of integer; {dlya zapisi znachenij elementov stolbcov v otdelnyu matricy} var matr : mass; {dlya obsheij matricij} stolb: stolbcij_matricij; {dlya zapisi znachenij stolbcov} m : integer; {znachenie dlya sravneniya} a1,b1 : integer; {dlya opredeleniya parametrov matricij} {*********************************************************************} procedure vvod_matricij; {procedyra dlya vivoda matricij na ekran} var i,j:integer; begin writeln('Vvedite a: '); readln(a1); writeln('Vvedite b: '); readln(b1); randomize; for i:=1 to a do begin for j:=1 to b do begin matr[i,j]:=random(10); end; end; end; {*********************************************************************} procedure matrica_na_ekrane; var i,j : integer; begin for i:=1 to a1 do begin for j:=1 to b1 do begin write(matr[i,j]:5); end; writeln;writeln; end; end; {*********************************************************************} function stolbec:integer; var m : integer; {peremennaya dlya sravneniya} j : integer; {znacheniya elementov v stolbcah} kolichestvo : integer; {peremennaya dlya podscheta kolichestva chisel bolshih, chem m} begin write('Vvedite peremennyu M: '); readln(m); kolichestvo := 0; end; {*********************************************************************} BEGIN clrscr; vvod_matricij; matrica_na_ekrane; stolbec; readln; END.
What to do next?
vvod_matricij
in cycles instead ofa
andb
should bea1
andb1
, although this does not really affect the filling of the matrix. for i: = 1 to a1 do begin for j: = 1 to b1 do begin matr [i, j]: = random (10); end; end; - andrybak