CODING:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],mul[10][10],m,n,p,q,i,j,k;
clrscr();
ab:
printf("Enter order of matrix A: ");
scanf("%d%d",&m,&n);
printf("Enter order of matrix B: ");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("\nError: multiplication not possible\nTry again....\n");
goto ab;
}
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
printf("Enter value of a[%d][%d]: ",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=1;i<=p;i++)
{
for(j=1;j<=q;j++)
{
printf("Enter value of b[%d][%d]: ",i,j);
scanf("%d",&b[i][j]);
}
}
printf("\nAnswer:\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=q;j++)
{
mul[i][j]=0;
for(k=1;k<=n;k++)
mul[i][j]=mul[i][j]+a[i][k]*b[k][j];
printf("%4d",mul[i][j]);
}
printf("\n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],mul[10][10],m,n,p,q,i,j,k;
clrscr();
ab:
printf("Enter order of matrix A: ");
scanf("%d%d",&m,&n);
printf("Enter order of matrix B: ");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("\nError: multiplication not possible\nTry again....\n");
goto ab;
}
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
printf("Enter value of a[%d][%d]: ",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=1;i<=p;i++)
{
for(j=1;j<=q;j++)
{
printf("Enter value of b[%d][%d]: ",i,j);
scanf("%d",&b[i][j]);
}
}
printf("\nAnswer:\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=q;j++)
{
mul[i][j]=0;
for(k=1;k<=n;k++)
mul[i][j]=mul[i][j]+a[i][k]*b[k][j];
printf("%4d",mul[i][j]);
}
printf("\n");
}
getch();
}
CODING |
OUTPUT |
For any query or suggestion please comment below...
No comments:
Post a Comment