คือว่าผมมีโค้ดปาสคาลอยู่อยากให้ท่านแอดมินช่วยหน่อยน่ะครับ
program ch10_13;
uses crt;
const
row_limit = 20;
column_limit = 20;
type
matrix = array[1..row_Limit,1..column_Limit] of integer;
var mat1,mat2,prod : matrix;
rows1,cols1,rows2,cols2 : integer;
product_defined : boolean;
procedure readmatrix(var mat : matrix; var rows, columns : Integer);
var i,j : integer;
begin
write('Enter number of rows & columns : ');
readln(rows,columns);
writeln('Enter the matrix rowwise : ');
for i := 1 to rows do
for j := 1 to columns do
read(mat[i,j]);
end;
procedure PrintMatrix(var mat : matrix; rows, columns : integer);
const field_width = 5;
var
i,j : integer;
begin
writeln;
for i := 1 to rows do
begin
for j := 1 to columns do
write(mat[i,j] : field_width);
writeln;
writeln;
end;
end;
procedure MatMultiply(var mat1, mat2, prod : matrix;
rows1,cols1,rows2,cols2 : integer;
var product_defined : boolean);
var
i,j,k,sum : Integer;
begin
product_defined := (cols1 = rows2);
if product_defined then
begin
for i := 1 to rows1 do
for j := 1 to cols2 do
begin
sum := 0;
for k := 1 to Cols1 do
sum := sum + mat1[i,k] * mat2[k,j];
prod[i,j] := Sum end;
end;
end;
begin
clrscr;
readMatrix(mat1,rows1,cols1);
writeln('First Matrix : ');
PrintMatrix(mat1,rows1,cols1);
readMatrix(mat2,rows2,cols2);
writeln('Second Matrix : ');
PrintMatrix(mat2,rows2,cols2);
MatMultiply(mat1,mat2,prod,rows1,cols1,rows2,cols2,product_defined);
if product_defined then
begin
writeln('Product : ');
PrintMatrix(prod,rows1,cols2);
end
else
begin
writeln('Product undefined -- number of columns ',cols1:1,' in first matrix');
writeln(' is not equal to number of rows ',rows2:1,' in second matrix');
end;
readln;
end.
อยากรู้ว่ามันคือโปรแกรมอะไร แล้วก็ขอคำอธิบายของแต่ละบรรทัดด้วยนะครับ
ขอขอบคุณอย่างสูงนะครับ
program ch10_13;
uses crt;
const
row_limit = 20;
column_limit = 20;
type
matrix = array[1..row_Limit,1..column_Limit] of integer;
var mat1,mat2,prod : matrix;
rows1,cols1,rows2,cols2 : integer;
product_defined : boolean;
procedure readmatrix(var mat : matrix; var rows, columns : Integer);
var i,j : integer;
begin
write('Enter number of rows & columns : ');
readln(rows,columns);
writeln('Enter the matrix rowwise : ');
for i := 1 to rows do
for j := 1 to columns do
read(mat[i,j]);
end;
procedure PrintMatrix(var mat : matrix; rows, columns : integer);
const field_width = 5;
var
i,j : integer;
begin
writeln;
for i := 1 to rows do
begin
for j := 1 to columns do
write(mat[i,j] : field_width);
writeln;
writeln;
end;
end;
procedure MatMultiply(var mat1, mat2, prod : matrix;
rows1,cols1,rows2,cols2 : integer;
var product_defined : boolean);
var
i,j,k,sum : Integer;
begin
product_defined := (cols1 = rows2);
if product_defined then
begin
for i := 1 to rows1 do
for j := 1 to cols2 do
begin
sum := 0;
for k := 1 to Cols1 do
sum := sum + mat1[i,k] * mat2[k,j];
prod[i,j] := Sum end;
end;
end;
begin
clrscr;
readMatrix(mat1,rows1,cols1);
writeln('First Matrix : ');
PrintMatrix(mat1,rows1,cols1);
readMatrix(mat2,rows2,cols2);
writeln('Second Matrix : ');
PrintMatrix(mat2,rows2,cols2);
MatMultiply(mat1,mat2,prod,rows1,cols1,rows2,cols2,product_defined);
if product_defined then
begin
writeln('Product : ');
PrintMatrix(prod,rows1,cols2);
end
else
begin
writeln('Product undefined -- number of columns ',cols1:1,' in first matrix');
writeln(' is not equal to number of rows ',rows2:1,' in second matrix');
end;
readln;
end.
อยากรู้ว่ามันคือโปรแกรมอะไร แล้วก็ขอคำอธิบายของแต่ละบรรทัดด้วยนะครับ
ขอขอบคุณอย่างสูงนะครับ