C Source Codes List | Source Code Home
Program : Program to multiply two matrices.
/* Prg. to multiply two matrices */
#include
#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("\n\nHow many rows in the first matrix? ");
scanf("%d",&nrows);
printf("\n\nHow many cols in the first matrix? ");
scanf("%d",&ncols);
printf("\n\nHow many rows in the second matrix? ");
scanf("%d",&mrows);
printf("\n\nHow 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("\n\nFirst table:\n");
readinput(a,nrows,ncols);
printf("\n\nSecond table:\n");
readinput(b,mrows,mcols);
computeproduct(a,b,c,nrows,ncols,mcols);
printf("\n\nProduct of the matrices is:\n\n");
writeoutput(c,nrows,mcols);
getch();
}
void readinput(int a[][MAXCOLS],int m,int n)
{
int row,col;
for (row=0;row
C Source Codes List | Source Code Home
|
|