thieumao

Tính tổng ma trận sử dụng chương trình con

Jun 19th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.03 KB | None | 0 0
  1. program tinhtong_matran;
  2. uses crt;
  3. type
  4.   mang=array[1..10,1..10] of integer;
  5. var
  6.   a,b,p:mang;
  7.   i,j,h,c,ha,ca,hb,cb:integer;
  8. procedure nhap(var m:mang; ch:char; var h,c:integer);
  9. begin
  10.   writeln('Nhap ma tran ',ch);
  11.   write('Nhap hang: ');
  12.   readln(h);
  13.   write('Nhap cot : ');
  14.   readln(c);
  15.   for i:=1 to h do
  16.     for j:=1 to c do
  17.       begin
  18.         write(ch,'[',i,',',j,']=');
  19.         readln(m[i,j]);
  20.       end;
  21. end;
  22. procedure xuat(var m:mang; ch:char; var h,c:integer);
  23. begin
  24.   writeln('In ma tran ' , ch);
  25.   for i:=1 to h do
  26.     begin
  27.       for j:=1 to c do write (m[i,j]:3);
  28.       writeln;
  29.     end;
  30. end;
  31. procedure tinhtong(var m,n,t:mang; h,c:integer);
  32. begin
  33.   for i:=1 to h do
  34.     for j:=1 to c do
  35.       t[i,j]:= m[i,j]+n[i,j];
  36. end;
  37. begin
  38.   clrscr;
  39.   nhap(a,'a',ha,ca);
  40.   nhap(b,'b',hb,cb);
  41.   xuat(a,'a',ha,ca);
  42.   xuat(b,'b',hb,cb);
  43.   if (ha=hb) and (ca=cb) then
  44.     begin
  45.       tinhtong(a,b,p,ha,ca);
  46.       xuat(p,'p',ha,ca);
  47.     end
  48.   else
  49.     writeln('Khong tinh tong duoc a,b');
  50.   readln;
  51. end.
Advertisement
Add Comment
Please, Sign In to add comment