Code:/* Matrix */ #include <stdio.h> void SetMatrixA(); void AddMatrixBtoA(); void DisplayMatrixA(); void MultiplyMatrixBtoA(); void TransposeMatrixA(); int rowsA; int rowsB; int columnsA; int columnsB; int A1[5][5]; int C1[5][5]; int main(void) { int rowsA; int columnsA; int A[5][5]; int choice; printf("\n"); printf("Matrix A\n"); for(columnsA=0; columnsA<3; columnsA++) { for(rowsA=0; rowsA<3; rowsA++) { A[0][0]= 1.0; A[0][1]= 0.0; A[0][2]= 0.0; A[1][0]= 0.0; A[1][1]= 1.0; A[1][2]= 0.0; A[2][0]= 0.0; A[2][1]= 0.0; A[2][2]= 1.0; printf("%5d", A[rowsA][columnsA]); } printf("\n"); } while(1) { printf("(1)Set Matrix A.\n"); printf("(2)Add a Matrix B\n"); printf("(3)Multiply with Matirx B.\n"); printf("(4)Transpose Matrix A.\n"); printf("(5)Exit.\n"); printf("\nPlease enter your choice: "); scanf("%d", &choice); switch(choice) { case 1: SetMatrixA(); break; case 2: AddMatrixBtoA(5, 5); break; case 3: MultiplyMatrixBtoA(5, 5); break; case 4: TransposeMatrixA(rowsA,columnsA); break; case 5: return 0; } } } void SetMatrixA() { int rowsA; int columnsA; int i; int j; printf("Please enter the number of rows for A: "); scanf("%d", &rowsA); printf("Please enter the number of columns for A: "); scanf("%d", &columnsA); printf("Please enter Elements of the first Matrix:\n"); for(i=0; i<rowsA; i++) { for(j=0; j<columnsA; j++) { printf("A[%d][%d]: ", i,j); scanf("%d", &A1[i][j]); } } printf("\nMatrix A is:\n\n"); for(i=0; i<rowsA; i++) { for(j=0; j<columnsA; j++) { printf("%5d", A1[i][j]); } printf("\n"); } } void DisplayMatrixA(int rowsA, int columnsA) { int i; int j; for(i=0; i< rowsA; i++) { for(j=0; j< columnsA; j++) { printf("%5d", A1[i][j]); } printf("\n"); } } void AddMatrixBtoA(int i, int j) { int B1[5][5]; printf("Please enter the number of rows for B: "); scanf("%d", &rowsB); printf("Please enter the number of columns for B: "); scanf("%d", &columnsB); printf("Please enter Elements of the second Matrix: \n"); for(i=0; i<rowsB; i++) { for(j=0; j<columnsB; j++) { printf("B[%d][%d]: ", i,j); scanf("%d", &B1[i][j]); } } printf("\nMatrix B is:\n\n"); DisplayMatrixA(rowsB, columnsB); printf("\nMatrix C is:\n\n"); for(i=0; i<rowsB; i++) { for(j=0; j<columnsB; j++) { C1[i][j]= A1[i][j] + B1[i][j]; printf("%5d", C1[i][j]); } printf("\n"); } } void MultiplyMatrixBtoA(int rowsB, int columnsB, int columnsA, int rowsA) { int i; int j; int k; int B1[5][5]; int n; printf("Please enter the number of rows for B: "); scanf("%d", &rowsB); printf("Please enter the number of columns for B: "); scanf("%d", &columnsB); printf("Please enter Elements of the second Matrix: \n"); for(k=0; k<rowsB; k++) { { for(n=0; n<columnsB; n++) { printf("B[%d][%d]: ", k,n); scanf("%d", &B1[k][n]); } } printf("\nMatrix B is:\n\n"); DisplayMatrixA(rowsB, columnsB); } for(i=0; i<rowsA; i++) { for(n=0; n<columnsB; n++) { C1[i][n]=0; for(k=0; k<columnsA; k++) C1[i][n]=C1[i][n] + A1[i][k] * B1[k][n]; } printf("\nMultiplication of Matrix:-\n"); for(i=0; i<rowsA; i++) for(i=0; i<rowsA; i++) { for(n=0; n<columnsB; n++) printf("5%d", C1[i][n]); printf("\n"); } } } void TransposeMatrixA(int rowsA, int columnsA) { int i; int j; int A2[5][5]; A2[j][i]= A1[i][j]; printf("\n\nTranspose of Matrix is:\n\n"); for(i=0; i<rowsA; i++) { for(j=0; j<columnsA; j++) { printf("%5d", A2[i][j]); } printf("\n"); } }