C > Beginners Lab Assignments
Program to Multiply Two Matrices
Program to Multiply Two Matrices #define MAXROWS 30 #define MAXCOLS 30 void readinput(int a[][MAXCOLS],int m,int n); void computeproduct(int a[][MAXCOLS],int b[][MAXCOLS],int c[][MAXCOLS],int m,int n,int p); void writeoutput(int c[][MAXCOLS],int m,int p); int z=0; void main() { /* char c;*/ int nrows,ncols,mrows,mcols; int a[MAXROWS][MAXCOLS],b[MAXROWS][MAXCOLS],c[MAXROWS][MAXCOLS]; clrscr(); printf(" How many rows in the first matrix? "); scanf("%d",&nrows); printf(" How many cols in the first matrix? "); scanf("%d",&ncols); printf(" How many rows in the second matrix? "); scanf("%d",&mrows); printf(" How many cols in the second matrix? "); scanf("%d",&mcols); if (ncols != mrows) { printf("The product of these matrices is not defined."); getch(); exit(0); } printf(" First table: "); readinput(a,nrows,ncols); printf(" Second table: "); readinput(b,mrows,mcols); computeproduct(a,b,c,nrows,ncols,mcols); printf(" Product of the matrices is: "); writeoutput(c,nrows,mcols); getch(); } void readinput(int a[][MAXCOLS],int m,int n) { int row,col; for (row=0;row
C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting