//Program for multiplication of two matrix.
#include<stdio.h>
#include<conio.h>
//Main Function
void main()
{
int i,j,k,n,a[10][10],b[10][10],c[10][10];
clrscr();
printf("Enter the order for matrix:");
scanf("%d",&n);
//Defining 1st matrix
printf("\nEnter elements for 1st matrix: \n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
//Defining 2nd matrix
printf("Enter elements for 2nd matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
//Initializing the 3rd i.e resultant matrix
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=0;
}
}
//Multiplication of two matrices
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
//Printing the resultant matrix
printf("Multiplication of 2 matrices:\n\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\t %d",c[i][j]);
}
printf("\n\n");
}
getch();
}//end of main.
/*Output
Enter the order for matrix:2
Enter elements for 1st matrix:
1 3
4 2
Enter elements for 2nd matrix:
6 4
1 3
Multiplication of 2 matrices:
9 13
26 22
*/
#include<stdio.h>
#include<conio.h>
//Main Function
void main()
{
int i,j,k,n,a[10][10],b[10][10],c[10][10];
clrscr();
printf("Enter the order for matrix:");
scanf("%d",&n);
//Defining 1st matrix
printf("\nEnter elements for 1st matrix: \n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
//Defining 2nd matrix
printf("Enter elements for 2nd matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
//Initializing the 3rd i.e resultant matrix
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=0;
}
}
//Multiplication of two matrices
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
//Printing the resultant matrix
printf("Multiplication of 2 matrices:\n\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\t %d",c[i][j]);
}
printf("\n\n");
}
getch();
}//end of main.
/*Output
Enter the order for matrix:2
Enter elements for 1st matrix:
1 3
4 2
Enter elements for 2nd matrix:
6 4
1 3
Multiplication of 2 matrices:
9 13
26 22
*/
Pankaj Gaikar is a
professional blogger
from Pune, India who writes on Technology, Android,
Gadgets, social media and latest tech updates at
Punk Tech
,
Being Android
&
Shake The Tech
. Email me
HERE
0 comments :
Post a Comment