#include <stdio.h>
#include<conio.h>
void main()
{
int m, n, p, q, i, j, k, sum = 0;
int a[10][10], b[10][10], mul[10][10];
printf("Enter the size of first matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements:-");
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
scanf("%d", &a[i][j]);
printf("Enter the size of second matrix\n");
scanf("%d%d", &p, &q);
if ( n != p )
printf("Matrices can't be multiplied");
else
{
printf("Enter the elements\n");
for ( i = 0 ; i < p ; i++ )
for ( j = 0 ; j < q ; j++ )
scanf("%d", &b[i][j]);
for ( i = 0 ; i < m ; i++ )
{
for ( j = 0 ; j < q ; j++ )
{
for ( k = 0 ; k< p ; k++ )
{
sum = sum + a[i][k]*b[k][j];
}
mul[i][j] = sum;
sum = 0;
}
}
printf("multiplication of matrices:-\n");
for ( i = 0 ; i < m ; i++ )
{
for ( j= 0 ; j < q ; j++ )
printf("%d\t", mul[i][j]);
printf("\n");
}
}
}
#include<conio.h>
void main()
{
int m, n, p, q, i, j, k, sum = 0;
int a[10][10], b[10][10], mul[10][10];
printf("Enter the size of first matrix\n");
scanf("%d%d", &m, &n);
printf("Enter the elements:-");
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
scanf("%d", &a[i][j]);
printf("Enter the size of second matrix\n");
scanf("%d%d", &p, &q);
if ( n != p )
printf("Matrices can't be multiplied");
else
{
printf("Enter the elements\n");
for ( i = 0 ; i < p ; i++ )
for ( j = 0 ; j < q ; j++ )
scanf("%d", &b[i][j]);
for ( i = 0 ; i < m ; i++ )
{
for ( j = 0 ; j < q ; j++ )
{
for ( k = 0 ; k< p ; k++ )
{
sum = sum + a[i][k]*b[k][j];
}
mul[i][j] = sum;
sum = 0;
}
}
printf("multiplication of matrices:-\n");
for ( i = 0 ; i < m ; i++ )
{
for ( j= 0 ; j < q ; j++ )
printf("%d\t", mul[i][j]);
printf("\n");
}
}
}
No comments :
Post a Comment