Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

KURSYAK

.PAS
Скачиваний:
0
Добавлен:
23.06.2018
Размер:
4 Кб
Скачать
program kursyak21;
uses CRT;
const SIZE=15;
var M,N,i,j: integer;
    temp:integer;
    mas:array[1..SIZE,1..SIZE] of integer;
    a:array[1..SIZE] of integer;
    fout:text;
    fin:text;




function getValue (min:integer; max:integer): integer; {begin of function}
var n:integer;
begin
read (n);
while ( (n<min) or (n>max) )
   do begin
   writeln ('Out of range');
   read(n);
   end;
getValue:=n;
end;

procedure printBigArray;
begin
for i:=1 to M do
    begin
    for j:= 1 to N do
        begin
        write (fout,mas[i,j]:5);
        write (mas[i,j]:5);
        end;
    writeln(fout,'');
    writeln;
    end;
end; {end of function}

procedure printSmallArray;  {begin of function}
var j,p1,p2,sum:integer;
    mul:real;
begin

for j:=1 to N do
    begin
    write(a[j]:5); {}
    write(fout,a[j]:5); {}
    end;
writeln;
writeln(fout,'');
p1:=0;
p2:=0;
for j:=1 to N do
    begin
    if a[j]=0 then
       if p1=0 then
          begin
          p1:=(j+1);
          end
       else
           if j=p1 then p1:=(j+1)
           else
               if p2=0 then
               p2:=j-1;
    end;

if (p1=0) or (p2=0) then begin
   writeln('V massive net dvuh nulevyh znachenyi mezhdu kotorimi est elementi');
   writeln(fout,'V massive net dvuh nulevyh znachenyi mezhdu kotorimi est elementi');
   end
else
    begin
    sum:=0;
    mul:=1.0;
    for j:=p1 to p2 do
        begin
        sum:=sum+a[j];
        mul:=mul*a[j];
        end;
    write('Summa:',sum,'   ');
    writeln('Mul:',mul:1:0);
    write(fout,'Summa:',sum,'   ');
    writeln(fout,'Mul:',mul:1:0);
    end;

end; {end of function}

begin  {MAIN BEGIN}

writeln ('Vvedite kol-vo strok v massive (1-',SIZE,')');
M:= getValue(1,SIZE);
writeln ('Vvedite kol-vo stolbcov v massive (1-',SIZE,')');
N:= getValue(1,SIZE);

{Filling and printing array }
writeln ('Kak zapolnit massiv? 1-random, 2-manual, 3-from file');
read (temp);
while (temp<1) or (temp>3) do begin
      writeln ('out of range');
      read(temp);
      end;

case temp of
1:
  begin
  writeln ('Vvedite max znachenie elementa');
  read (temp);

  for i:=1 to M do
    for j:= 1 to N do
        mas[i,j]:=random(temp);
    end;

2:    {manual fill}
  begin
  for i:=1 to M   do
    begin
    writeln ('Vvedite elementi stroki #',i);
    for j:=1 to N do
        read(mas[i,j]);
    end;
  end;
3:    {fill from fill}
  begin
  assign (fin,'IN.TXT');
  reset(fin);
  for i:=1 to M   do
    for j:=1 to N do
        read(fin,mas[i,j]);

  end;

end;

assign(fout,'out.txt');
rewrite(fout);
writeln;
writeln ('Ishodnyi massiv:');
writeln (fout,'Ishodnyi massiv:');
printBigArray;
{-----------------------------------}

{Transformation and print on screen}
for j:=1 to N do
    begin
    temp:=mas[1,j];
    for i:=2 to M do
        if (temp>mas[i,j])
           then temp:=mas[i,j];
    for i:=1 to M do
        mas[i,j]:=mas[i,j]*temp;
    end;

writeln;
writeln(fout,'');
writeln ('Preobrazovannyi massiv:');
writeln (fout,'Preobrazovannyi massiv:');
printBigArray;
writeln;
writeln(fout,'');
{------------------------------------}

{Creating and printing new arrays}
if M<4 then begin
   writeln ('Array has only ',M,' string(s)');
   writeln (fout,'Array has only ',M,' string(s)');
   end
else M:=4;
for i:=1 to M do
    begin
    for j:=1 to N do
        a[j]:=mas[i,j];
    write('string ',i,': ');
    write(fout,'string ',i,': ');
    printSmallArray;
    writeln;
    writeln(fout,'');
    end;
{--------------------------------------}
close(fout);
end.