Logo source
Hey! I'm back again with another C code problem and its the multiplication of two array.
For this code, at 1st take input of two array(3×3).Then I multiplied the array. Here goes the code.
Problem : Write a programme in c to Multiply two array (3×3)
Solution :
#include<stdio.h>
void input(int row,int col,int matrix[row][col])
{
int i,j;
for(i=0; i<row; i++)
{
for(j=0; j<col; j++)
{
printf("Element [%d],[%d] : ",i,j);
scanf("%d",&matrix[i][j]);
}
}
}
int main()
{
int matA[3][3],matB[3][3],result[3][3],i,j,k,sum=0;
input(3,3,matA);
printf("First matrix:\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf("%d\t",matA[i][j]);
}
printf("\n");
}
input(3,3,matB);
printf("Second matrix:\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf("%d\t",matB[i][j]);
}
printf("\n");
}
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
for(k=0; k<3; k++)
{
sum=sum+matA[i][k]matB[k][j];
}
result[i][j]=sum;
}
}
printf("Result\n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf("%d\t",result [i][j]);
}
printf("\n");
}
}
If you build and run this programme, you'll get a output like this!
You can easily multiply two array in this method. Hope, you all will like this.
Thats all for today.Tell me in the comment box, if you want more C code problem like this or not! I'll do this for you.