Assignment 4
Assignment 4
Assignment 4
#include<stdio.h>
void main()
{
int p[50][50],q[50][50],multi[50][50],r,c,i,j,k;
printf("Enter the number of rows:");
scanf("%d",&r);
printf("Enter the number of columns:");
scanf("%d",&c);
printf("\n Enter the elements of first matrix:");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf(“\n a%d%d=”,i+1,j+1);
scanf("%d",&p[i][j]);
}
}
printf("enter the element of second matrix=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf(“\n a%d%d= “,i+1,j+1);
scanf("%d",&q[i][j]);
}
}
printf("multiplication of the matrix=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
multi[i][j]=0;
for(k=0;k<c;k++)
{
multi[i][j]+=p[i][k]*q[k][j];
}}}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",multi[i][j]);
}
printf("\n");
}
return 0;
}
Output:
Enter the number of rows:3
Enter the number of columns:3
Enter the elements of first matrix:
a11=1
a12=1
a13=1
a21=2
a22=2
a23=2
a31=3
a32=3
a33=3
Enter the element of second matrix=
a11=1
a12=1
a13=1
a21=2
a22=2
a23=2
a31=3
a32=3
a33=3
multiplication of the matrix=
6 6 6
12 12 12
18 18 18
}
}
Output:
Enter the number of rows:2
Enter the number of columns:3
10 8 6