V
V
Vinogradov2022-02-24 22:51:01
Delphi
Vinogradov, 2022-02-24 22:51:01

How to change the algorithm for Lazarus?

I need to transfer the algorithm of this code to Lasarus form StringGrid2.Cells

uses crt;
var
a:array[1..10,1..10] of integer;
b:array[1..10,1..10] of real;
i,j,min,n,c:integer;
begin
  randomize; clrscr;
  write('N='); readln(n); min:=100;
  writeln('Kak vvesty danniye:');
  writeln('1. Random');
  writeln('2. Vruchnuyu'); readln(c);
  writeln('Matrix:');
 
  case c of
  1: begin
        for i:=1 to n do begin
          for j:=1 to n do begin
            a[i,j]:=-100+random(200);
            if (ABS(a[i,j])<ABS(min)) and (a[i,j]<>0) then min:=a[i,j];
            write(a[i,j]:5);
          end;
          writeln;
        end;
      end;
  2: begin
       for i:=1 to n do
         for j:=1 to n do begin
           readln(a[i,j]);
         if (ABS(a[i,j])<ABS(min)) and (a[i,j]<>0) then min:=a[i,j];
         end;
      end;
  end;
 
  writeln('Min = ',min);
  writeln('Result:');
  for i:=1 to n do begin
    for j:=1 to n do begin
      b[i,j]:=a[i,j]/min;
      if frac(b[i,j])<>0 then write(b[i,j]:6:2,' ')
        else write(b[i,j]:6:0,' ');
    end;
    writeln;
  end;
  readkey;
end.


It runs the application but throws an error when executing the invalid integer algorithm
6217e0687d894030070140.jpeg

here is my code

var
i,j,n,c:integer;
min:longint;

begin
clrscr;
min:=10000000;
n:=StrToInt(Edit1.Text)-1;

if n>9 then begin
  ShowMessage('Слишком большой размер матрицы');
  exit;
end;

StringGrid2.Clean;

begin
      for i:=1 to n do
        for j:=1 to n do begin

        if (ABS(StrToInt(StringGrid1.Cells[i, j]))<ABS(min)) and (StrToInt(StringGrid1.Cells[i, j])<>0) then
        min:=ABS(StrToInt(StringGrid1.Cells[i, j]));
        end;
     end;
for i:=1 to n do begin
  for j:=1 to n do begin
    StringGrid2.Cells[i, j]:= Format('%5.1n', [StrToInt(StringGrid1.Cells[i, j])/min]);

    if frac(StrToInt(StringGrid2.Cells[i, j]))<>0 then StrToInt(StringGrid2.Cells[i, j])
    else StringGrid2.Cells[i, j]:= Format('%5.1n', [StrToInt(StringGrid1.Cells[i, j])/min]);



  end;

end;


end;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hemul GM, 2022-02-24
@VinogradovDionis

8,2 is not an integer. This is a fractional, real number.
You need to translate the string into Float, and not into int

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question