thieumao

Tổng 2 ma trận - đọc ghi file

Apr 30th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.86 KB | None | 0 0
  1. uses crt;
  2. type
  3.   mang = array[1..10,1..10] of byte;
  4. var
  5.   f:text;
  6.   i,j:byte;
  7.   a,b,c:mang;
  8.   n:byte;
  9. begin
  10.   clrscr;
  11.   {$I-}
  12.   assign(f,'input.txt');
  13.   {Doc file}
  14.   reset(f);
  15.   {$I+}
  16.  
  17.   {Kiem tra ton tai file khong}
  18.   if IOResult<>0 then
  19.     begin
  20.       write('Khong tim thay file');
  21.       readln;
  22.       exit;
  23.     end;
  24.  
  25.   readln(f,n);
  26.   readln(f);
  27.   for i:=1 to n do
  28.     begin
  29.       for j:=1 to n do read(f,a[i,j]);
  30.       readln(f);
  31.     end;
  32.   readln(f);
  33.   for i:=1 to n do
  34.     begin
  35.       for j:=1 to n do read(f,b[i,j]);
  36.       readln(f);
  37.     end;
  38.   close(f);
  39.   {tinh tong}
  40.   for i:=1 to n do
  41.     for j:=1 to n do
  42.       c[i,j]:=a[i,j]+b[i,j];
  43.  
  44.   {ghi file}
  45.   append(f);
  46.   writeln(f);
  47.   writeln(f,'Ma tran c');
  48.   for i:=1 to n do
  49.     begin
  50.       for j:=1 to n do write(f,c[i,j]:3);
  51.       writeln(f);
  52.     end;
  53.   close(f);
  54. end.
Advertisement
Add Comment
Please, Sign In to add comment