SHARE
TWEET

Untitled

a guest Oct 21st, 2019 70 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. var
  15.     size: integer;
  16.     cols: integer;
  17.     rows: integer;
  18.     nums1: tnums;
  19.     nums2: tnums;
  20.     numsSum: tnums;
  21.     isCorrect: boolean;
  22.     input: tInput;
  23.     f: textfile;
  24.     matr1: tNums;
  25.     matr2: tNums;
  26.  
  27.  
  28. function ReadMatrFromFile(mass: tNums; path: String): tNums;
  29. begin
  30.     AssignFile(f, path);
  31.     Reset(f);
  32.     ReadLn(f, size);
  33.     SetLength(mass, size, size);
  34.     for rows := 0 to High(mass) do
  35.     begin
  36.         for cols := 0 to High(mass) do
  37.         begin
  38.             Read(f, mass[rows,cols]);
  39.             Write(' ', mass[rows,cols]);
  40.         end;
  41.         Writeln('');
  42.     end;
  43.     Writeln('--------------------');
  44.     Result := mass;
  45. end;
  46.  
  47.  
  48. function SumOfMatrs(Firstmass, Secondmass:tNums; size: integer): tNums;
  49. var
  50.     rows, cols: integer;
  51. begin
  52.     matr1 := ReadMatrFromFile(nums1, 'c:\Users\Богданчик\Documents\laba\matrix1.txt');
  53.     matr2 := ReadMatrFromFile(nums2, 'c:\Users\Богданчик\Documents\laba\matrix2.txt');
  54.     Writeln('Полученная сумма матриц: ');
  55.     for rows := 0 to high(Firstmass) do
  56.     begin
  57.         for cols := 0 to high(Firstmass) do
  58.         begin
  59.             Firstmass[rows, cols] := Firstmass[rows, cols] + Secondmass[rows, cols];
  60.             Write(' ', Firstmass[rows, cols]);
  61.         end;
  62.         Writeln;
  63.     end;
  64.     Writeln('--------------------');
  65.     Result := Firstmass;
  66. end;
  67.  
  68.  
  69. procedure SaveMatrSumInFile(numsSum: tnums);
  70. begin
  71.     AssignFile(f,'c:\Users\Богданчик\Documents\laba\matrixSum.txt');
  72.     Rewrite(f);
  73.     for rows := 1 to size do
  74.             for cols := 1 to size do
  75.                 Write(f,numsSum[rows,cols]);
  76.     Writeln;
  77.     Closefile(f);
  78.     Writeln('Файл сохранен.');
  79. end;
  80.  
  81.  
  82. begin
  83.     Writeln('Данная программа складывает две треугольные матрицы, в которых только элементы над главной диагональю отличны от нуля, порядка n.');
  84.     SumOfMatrs(nums1, nums2);
  85.     SaveMatrSumInFile(numsSum);
  86. 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