Code:
#include<stdio.h>
void showmatrix(int matrix[][], int row, int column)
{
int i, j ;
int A[row][column];
printf("Current Matrix is : \n");
for(i=0; i<row; i++)
{
for(j =0; j<column; j++)
{ printf("%d\t", A[i][j]);
} printf("\n");
}
printf("\n");
}
void setMatrix(int matrix[][], int row, int column)
{
int i, j;
int A[row][column];
for(i=0; i<row; i++)
{
for(j =0; j<column; j++)
{
printf("please input element (%d, %d) of the matrix:", i, j); scanf("%d", &A[i][j]);
}
}
}
void replaceA(int matrix[][4],int row,int column)
{
int i, j;
int A[row][column];
printf("Please enter the number of rows for matrix:"); scanf("%d", &row);
printf("Please enter the number of columns for matrix:"); scanf("%d", &column);
for(i=0; i<row; i++)
{
for(j =0; j<column; j++)
{
printf("please input element (%d, %d) of the matrix:", i, j); scanf("%d", &A[i][j]);
}
}
}
int showmenu(int matrix[][], int row, int column)
{
int choice = 0;
printf("******MENU******\n");
/* showmatrix(matrix, row, column);*/
printf("(1) Set matrix A\n");
printf("(2) Add a matrix B (matrix addition) \n");
printf("(3) Multiply with a matrix B (matrix multiplication) \n");
printf("(4) Transpose matrix A\n");
printf("(5) Exit \n");
printf("Please give your choice: "); scanf("%d", &choice);
return choice;
}
void replaceB(int matrixB[][],int row, int column)
{ int i, j;
int B[row][column];
for(i=0; i<row; i++)
{
for(j =0; j<column; j++)
{
printf("please input element (%d, %d) of the matrix:", i, j); scanf("%d", &B[i][j]);
}
}
}
void add(int matrixA[][], int matrixB[][], int matrixC[][], int row, int column)
{ int i,j;
int A[row][column];
int B[row][column];
int C[row][column];
for(i=0; i<row; i++)
{
for(j =0; j<column; j++)
{ C[i][j] = A[i][j] +B[i][j];
A[i][j] = C[i][j]; }
}
}
/*
void add(int matrixA[][], int matrixB[][], int row, int column)
{
int i, j;
int A[row][column];
int B[row][column];
int C[row][column];
int value;
{
for(i=0; i<row; i++)
{
for(j =0; j<column; j++)
{
printf("please input element (%d, %d) of the matrix:", i, j); scanf("%d", &value);
B[i][j] = value;
}
}
}
for(i=0; i<row; i++)
{
for(j =0; j<column; j++)
{ C[i][j] = A[i][j] + B[i][j];
A[i][j] = C[i][j];
}
}
}*/
/*
void multiply(int matrixA[][4], int rowA, int columnA, int matrixB[][4], int rowB, int columnB)
{
int i,j, k;
int A[i][j],B[i][k];
int column, row, rowA, columnA, rowB, columnB, value, multi;
rowA = row;
columnA = column;
rowB = columnA;
printf("Please enter the number of columns for matrix A: ")
scanf("%d", &columnB);
for(i=0; i<rowB; i++)
{
for(k=0; k<columnB; k++)
{
printf("please input element (%d, %d) of the matrix:", i, j); scanf("%d", &value);
B[i][k] = value
}
}
for(i=0; i<rowA; i++)
{
for(j=0; j<columnB;j++)
{ multi = (A[i][j] * B[i][k]) + (A[i][j++] * B[i++][k];
A[i][j] = multi;
}
void transpose(int matrix[][4], int row, int column)
{
}
*/
int main()
{
int matrixA[4][4];
int matrixB[4][4];
int matrixC[4][4];
int row=0, column =0;
int rowB=0, columnB = 0;
/* this variable is used to store the user's choice for the menu system */
int choice = -1;
printf("Please enter the number of rows for matrix:"); scanf("%d", &row);
printf("Please enter the number of columns for matrix:"); scanf("%d", &column);
setMatrix(matrixA, row, column);
showmatrix(matrixA,row,column);
choice = showmenu(matrixA,row,column);
while(1)
{
if(choice == 1)
{ replaceA(matrixA,row,column) ;
showmatrix(matrixA,row,column);
}
if(choice == 2)
{ replaceB(matrixB,row,column);
add(matrixA, matrixB, matrixC,row, column);
showmatrix(matrixA,row,column); }
else if(choice ==5)
{ break;}
choice = showmenu(matrixA,row,column);
}
return 0;
}
i figured out the first problem