Saturday, 7 January 2017

multiplication of matrix in c

Tags


#include<stdio.h>

#include<conio.h>

void main()

{
int a[10][10],b[10][10],multi,r1,c1,r2,c2,i,j,k;

clrscr();

printf(“enter row and column for first matrix:”);

scanf(“%d%d”,&r1,&c1);

printf(“enter row and column for second matrix:”);

while(c1!=r2)

{
printf(“error! column of first matrix not equal to row of second:”);

printf(“enter row and column for first matrix:”

scanf(“%d%d”,&r1,&c1);

printf (“enter row and column for second matrix:”);

scanf(“%d%d”,&r1,&c2);

}

printf(“\n enter elements of matix 1:\n”);

for(i=0;i<r2;++i)

for(j=0;j<c2;j++)

{

printf(“enter elements  a%d%d:”,i+1,J+1);

scanf(“%d”,&a[i][j]);

}



printf(“\n enter elements of matix 2:\n”);

for(i=0;i<r2;++i)

for(j=0;j<c2;j++)

{

printf(“enter elements  b%d%d:”,i+1,J+1);

scanf(“%d”,&b[i][j]);

}

for(i=0;i<r1;++i)

for(j=0;j<c2;++j)

{

mult[i][j]=0;

}

for (i=0;i<r1;++i)

for(j=0;j<c2;++j)

for(k=0;k<c1;++k)

{

mult[i][j]+=a[i][k]*b[k][j];

}

printf(“\n output matrix:\n”);

for(i=0;i<r1;++i)

for(j=0;j<c2;++j)

{

printf(“%d   ”,mult[i][j]);

if(j==c2-1)

printf(“\n\n”);

}

getch();

}