/* Program to input, multiply, and print two matrices. */ #define MAX 5 /* maximum row & column sizes */ #include #include /* for exit() */ int rowsizes[2], colsizes[2]; /* row and column sizes of the input matrices. */ char matrix_name[2][8] = { /* names for the input matrices */ "first", "second" }; float A[MAX][MAX], B[MAX][MAX], C[MAX][MAX]; /* the matrices */ /* function definitions: */ void get_size_and_check(int which_matrix) ; void input_matrix(int which_matrix, float mat[MAX][MAX]); void form_product(void); void display_result(void); main() { int i; /* Ask and check sizes of matrices. */ for (i=0; i<2; i++) { get_size_and_check(i /* which matrix */); } if (colsizes[0] != rowsizes[1]) { /* Sizes compatible? */ printf("Matrix sizes are not compatible.\n"); exit(EXIT_FAILURE); } /* Input matrices. */ input_matrix(0 /* which matrix */, A); input_matrix(1 /* which matrix */, B); form_product(); /* Multiply giving matrix C. */ display_result(); /* Display matrix C. */ return 0; } void get_size_and_check(int which_matrix) { printf ( "Enter row and column sizes for the %s matrix: ", matrix_name[which_matrix] ); scanf("%d%d", &rowsizes[which_matrix], &colsizes[which_matrix]); if (rowsizes[which_matrix] > MAX || colsizes[which_matrix] > MAX) { printf("Error: maximum %d rows and columns.\n", MAX); exit(EXIT_FAILURE); } } void input_matrix(int which_matrix, float mat[MAX][MAX]) { int row, col; printf("Enter %s matrix:\n", matrix_name[which_matrix]); for (row=0; row