procedure ascendentes(n,m: byte ; mat: tipomat);
var
i,j,suma: byte ;
begin
suma:=0;
i:=2;
for j:=1 to m do
begin
while (i<=n) and (mat[i,j]>mat[i-1,j]) do
begin
i:= i+1;
suma:= suma+1;
end;
end;
writeln(i,'...',suma);
if i> n then
writeln('cumple con ',suma)
else
writeln('no cumple ');
end;
// It doesn't calculate the number of columns correctly. I'm using pascal
The problem you have is that you have not yet developed the logic that correctly solves the problem. My advice is that, considering how a program works, solve the problem first using paper and pencil.
One way I can think of is to declare a boolean variable
EsAscendente
and, for each column, start by assuming it is ascending and go through it row by row. If a case is found where the cell of the current row is not greater than the cell of the previous row, set this variable to false and abort the cycle that goes through the rows (it is not necessary to see more rows, it is already known that the column is not ascending).At the end of this cycle, if the variable
EsAscendente
has a true value, we increment the variable by oneContador
and proceed to the next column.I've made an example with a couple of constants and an array type called
TMatriz
:Running my full example, I get output like the following: