WRITE A C PROGRAM FOR MATRIX MULTIPLICATION
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,m,n,p,a[10][10],b[10][10],c[10][10];
printf("Enter the number of rows and column:");
scanf("%d%d",&m,&n);
p=n;
printf("Enter the first matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("Enter the second matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=0;
for(k=0;k<p;k++)
{
c[i][j]=c[i][j]+a[i][j]*b[i][j];
}
}
}
printf("The resultant matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}
getch();
}
Output:
Enter the number of rows and column:2
2
Enter the first matrix:
1 1
1 1
Enter the second matrix:
1 1
1 1
The resultant matrix:
2 2
2 2
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,m,n,p,a[10][10],b[10][10],c[10][10];
printf("Enter the number of rows and column:");
scanf("%d%d",&m,&n);
p=n;
printf("Enter the first matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("Enter the second matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=0;
for(k=0;k<p;k++)
{
c[i][j]=c[i][j]+a[i][j]*b[i][j];
}
}
}
printf("The resultant matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}
getch();
}
Output:
Enter the number of rows and column:2
2
Enter the first matrix:
1 1
1 1
Enter the second matrix:
1 1
1 1
The resultant matrix:
2 2
2 2
No comments:
Post a Comment