C PROGRAM |
C program to calculate matrix multiplication using a two-dimensional array
#include <stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],rows,columns,i,j,k;
clrscr();
printf("enter the number of rows \n");
scanf("%d",&rows);
printf("enter the number of columns \n");
scanf("%d",&columns);
printf("enter the numbers of the first matrix \n");
for(i=0; i<rows; i++)
{
for(j=0; j<columns; j++)
{
scanf("%d",&a[i][j]);
}
}
printf ("enter the numbers of the second matrix \n");
for(i=0; i<rows; i++)
{
for(j=0; j<columns; j++)
{
scanf("%d",&b[i][j]);
}
}
printf ("multiplication of matrix \n");
for(i=0; i<rows; i++)
{
for(j=0; j<columns; j++)
{
c=0;
for(k=0; k<columns; k++)
{
c+=a[i][k]*b[k][j];
}
}
}
for(i=0; i<rows; i++)
{
for(j=0; j<columns; j++)
{
printf (" \n %d",c);
}
}
getch();
}
OUTPUT :
2
enter the number of columns
2
enter the numbers of the first matrix
1 1
1 1
enter the numbers of the second matrix
2 2
2 2
multiplication of matrix
4
4
4
4
[Process completed (code 10) - press Enter]
No comments:
Post a Comment