SHARE
TWEET

laba.work.2.3

a guest Oct 21st, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. {$R *.res}
  6.  
  7. uses
  8.   System.SysUtils;
  9.  
  10. type
  11.     tNums = array of array of integer;
  12.     tInput = (ChooseKeyboard, ChooseFile);
  13.  
  14. function ReadMatrFromFile(mass: tNums; path: String): tNums;
  15. var
  16.     size, cols, rows: integer;
  17.     f: textfile;
  18. begin
  19.     AssignFile(f, path);
  20.     Reset(f);
  21.     ReadLn(f, size);
  22.     SetLength(mass, size, size);
  23.     for rows := 0 to High(mass) do
  24.     begin
  25.         for cols := 0 to High(mass) do
  26.         begin
  27.             Read(f, mass[rows,cols]);
  28.             Write(' ', mass[rows,cols]);
  29.         end;
  30.         Writeln('');
  31.     end;
  32.     Writeln('--------------------');
  33.     Result := mass;
  34. end;
  35.  
  36.  
  37. function SumOfMatrs(Firstmass, Secondmass: tNums; size: integer): tNums;
  38. var
  39.     rows, cols: integer;
  40. begin
  41.     Firstmass := ReadMatrFromFile(Firstmass, 'c:\Users\Богданчик\Documents\laba\matrix1.txt');
  42.     Secondmass := ReadMatrFromFile(Secondmass, 'c:\Users\Богданчик\Documents\laba\matrix2.txt');
  43.     Writeln('Полученная сумма матриц: ');
  44.     for rows := 0 to high(Firstmass) do
  45.     begin
  46.         for cols := 0 to high(Firstmass) do
  47.         begin
  48.             Firstmass[rows, cols] := Firstmass[rows, cols] + Secondmass[rows, cols];
  49.             Write(' ', Firstmass[rows, cols]);
  50.         end;
  51.         Writeln;
  52.     end;
  53.     Result := Firstmass;
  54. end;
  55.  
  56.  
  57. procedure SaveMatrSumInFile(Firstmass: tnums);
  58. var
  59.     rows, cols: integer;
  60.     f: textfile;
  61. begin
  62.     AssignFile(f,'c:\Users\Богданчик\Documents\laba\matrixSum.txt');
  63.     Rewrite(f);
  64.     for rows := 0 to high(FirstMass) do
  65.             for cols := 0 to high(FirstMass) do
  66.                 Write(f,FirstMass[rows,cols]);
  67.     Writeln;
  68.     Closefile(f);
  69.     Writeln('Файл сохранен.');
  70. end;
  71.  
  72.  
  73. var
  74.     massSum: tnums;
  75.     mass1: tNums;
  76.     mass2: tNums;
  77.     size: integer;
  78.  
  79. begin
  80.     Writeln('Данная программа складывает две треугольные матрицы, в которых только элементы над главной диагональю отличны от нуля, порядка n.');
  81.     SumOfMatrs(mass1, mass2, size);
  82.     SaveMatrSumInFile(massSum);
  83.     Readln;
  84. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top