|
|
@@ -0,0 +1,80 @@
|
|
|
+extern void printInt( int val);
|
|
|
+extern void printFloat( float val);
|
|
|
+
|
|
|
+extern int scanInt( );
|
|
|
+extern float scanFloat( );
|
|
|
+
|
|
|
+extern void printSpaces( int num);
|
|
|
+extern void printNewlines( int num);
|
|
|
+
|
|
|
+
|
|
|
+export int main()
|
|
|
+{
|
|
|
+ //Read dimensions of matrix from input
|
|
|
+ int rowsMatrixA =5;
|
|
|
+ int colMatrixA = 5;
|
|
|
+
|
|
|
+ int rowsMatrixB =5;
|
|
|
+ int colMatrixB = 5;
|
|
|
+
|
|
|
+ int[rowsMatrixA, colMatrixA] matrixA;
|
|
|
+ int[rowsMatrixB, colMatrixB] matrixB;
|
|
|
+ int[rowsMatrixA, colMatrixB] matrixProduct;
|
|
|
+
|
|
|
+ //Product cannot be done if the following condition does not stand
|
|
|
+ if (colMatrixA == rowsMatrixB)
|
|
|
+ {
|
|
|
+ //Fill in Matrix A
|
|
|
+ for (int i = 0, rowsMatrixA)
|
|
|
+ {
|
|
|
+ for (int j = 0, colMatrixA)
|
|
|
+ {
|
|
|
+ matrixA[i, j] = i + j;
|
|
|
+ printInt(matrixA[i, j]);
|
|
|
+ printSpaces(3);
|
|
|
+ }
|
|
|
+ printNewlines(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ //Fill in Matrix B
|
|
|
+ for (int i = 0, rowsMatrixB)
|
|
|
+ {
|
|
|
+ for (int j = 0, colMatrixB)
|
|
|
+ {
|
|
|
+ matrixB[i, j] = i + j;
|
|
|
+ printInt(matrixB[i, j]);
|
|
|
+ printSpaces(3);
|
|
|
+ }
|
|
|
+ printNewlines(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ //Do Multiplication
|
|
|
+ for (int i = 0, rowsMatrixA)
|
|
|
+ {
|
|
|
+ for (int j = 0, colMatrixB)
|
|
|
+ {
|
|
|
+ matrixProduct[i, j] = 0;
|
|
|
+ for (int m = 0, colMatrixA)
|
|
|
+ {
|
|
|
+ matrixProduct[i, j] = matrixProduct[i, j] + (matrixA[i, m] * matrixB[m,j]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0, rowsMatrixA)
|
|
|
+ {
|
|
|
+ for (int j = 0, colMatrixB)
|
|
|
+ {
|
|
|
+ printInt(matrixProduct[i, j]);
|
|
|
+ printSpaces(3);
|
|
|
+ }
|
|
|
+ printNewlines(1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|