c program code for matrix multiplication
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20][20],b[20][20],c[20][20],i,j,m,n,m2,n2,k;
clrscr();
printf("enter the rows and columns of the first matrics\n");
scanf("%d%d",&m,&n);
printf("Enter the first matrics\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]); //reads first matrics
}
}
printf("enter the rows and columns of the SECOND matrics\n");
scanf("%d%d",&m2,&n2);
printf("Enter the second matrics\n");
for(i=0;i<m2;i++)
{
for(j=0;j<n2;j++)
{
scanf("%d",&b[i][j]); reads second matrics
}
}
printf("The matrics product \n");
for(i=0;i<m;i++)
{
for(j=0;j<n2;j++)
{ c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
printf("%d ",c[i][j]);
}
printf("\n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20][20],b[20][20],c[20][20],i,j,m,n,m2,n2,k;
clrscr();
printf("enter the rows and columns of the first matrics\n");
scanf("%d%d",&m,&n);
printf("Enter the first matrics\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]); //reads first matrics
}
}
printf("enter the rows and columns of the SECOND matrics\n");
scanf("%d%d",&m2,&n2);
printf("Enter the second matrics\n");
for(i=0;i<m2;i++)
{
for(j=0;j<n2;j++)
{
scanf("%d",&b[i][j]); reads second matrics
}
}
printf("The matrics product \n");
for(i=0;i<m;i++)
{
for(j=0;j<n2;j++)
{ c[i][j]=0;
for(k=0;k<n;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
printf("%d ",c[i][j]);
}
printf("\n");
}
getch();
}
No comments:
Post a Comment