/* C program to multiply two matrices */
#include"stdio.h"
#include"conio.h"
void main()
{
clrscr();
int i,j,k,a[20][20],b[20][20],c[20][20],m,n,p,q;
printf("enter the no of rows n columns of matrix A");
scanf("%d %d",&m,&n);
printf("enter the no of rows n col for matrix B");
scanf("%d %d",&p,&q);
if(n==p){
printf("enter the elements for matrix A");
for(i=0;i< m;i++)
{
for(j=0;j< n;j++){
scanf("%d",&a[i][j]);
}
}
printf("enter the elements for the matrix B");
for(i=0;i< p;i++)
{
for(j=0;j< q;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("the product of the matrices is");
for(i=0;i< m;i++){
printf("\n");
for(j=0;j< q;j++){
c[i][j]=0;
for(k=0;k< n;k++){
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}}}
for(i=0;i< m;i++){
printf("\n");
for(j=0;j< q;j++){
printf("%d \t",c[i][j]);
}
printf("\n");
}
}
else
printf("matrices cannot be multiplied");
getch();
}
Tuesday, September 2, 2008
Matrix multiplication
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment