Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

MATRIX MULTIPLICATION

AIM:
To write a c-program to perform matrix multiplication.
ALGORITHM:
STEP1: Start
STEP2: include necessary header files
STEP3: get necessary in particular data type
STEP4: get the number of rows and columns using printf() and scanf() functions
STEP5: initialize separate for loops to print the elements of matrix A and B
STEP6: use another for loop to print the multiplied elements of A and B
STEP7: stop

PROGRAM:

#include<stdio.h>
#include<stdlib.h>
int main(){
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
printf("enter the number of row=");
scanf("%d",&r);
printf("enter the number of column=");
scanf("%d",&c);
printf("enter the first matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the second matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{

S.Devi sri monica 21CSE005


scanf("%d",&b[i][j]);
}
}

printf("multiply of the matrix=\n");


for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",mul[i][j]);
}
printf("\n");
}
return 0;
}

OUTPUT:

Enter the no of rows:3

Enter the no of columns:3

Enter first matrix elements:

223

145

147

S.Devi sri monica 21CSE005


Enter second matrix element:

458

139

123

Multiply of the matrix:

13 22 43

13 27 59

15 31 65

RESULT:

Thus the above code is written in c and successfully executed.

S.Devi sri monica 21CSE005


S.Devi sri monica 21CSE005

You might also like