В каждой строке матрицы  A(N, N)  определите наибольшее простое число. Если в строке нет простых чисел, выдайте соответствующее сообщение — Pascal(Паскаль)

const
  nmax=25;
var
  r:array[1..nmax,1..nmax] of integer;
  s:array[1..nmax,1..nmax] of integer;
  i,j,k,f,n,m:integer;
  maxj:integer;
  isSimple:boolean;
begin
  repeat
    write('Kol-vo strok-> ');
    readln(n);
    write('Kol-vo stolbtsov-> ');
    readln(m);
  until (n in [1..nmax]) and (m in [1..nmax]);
  randomize;
  for i:=1 to n do
    for j:=1 to m do
      begin
        r[i,j]:=random(100)+1;
        write(r[i,j]:5);
        if j=m then 
          writeln;
      end;
  for i:=1 to n do
    begin
      f:=0;
      for j:=1 to m do
        begin
          isSimple:=true;
          for k:=2 to r[i,j] div 2 do
            if r[i,j] mod k=0 then
              begin
                isSimple:=false;
                break;
              end;
          if isSimple then
            begin
              inc(f);
              s[i,f]:=r[i,j];
            end;
        end;
    end;
  writeln;
  for i:=1 to n do
    begin
      maxj:=1;
      for j:=1 to m do
        if s[i,j]>s[i,maxj] then
          maxj:=j;
      if s[i,maxj]=0 then
        writeln('V stroke ',i,' net prostyh chisel.')
      else
        writeln('Max. prostoe chislo v ',i,' stroke ',s[i,maxj],'.');
    end;
  readln;
end.

Leave a Comment

+ 18 = 28