Search:

Submit Article

# PROGRAM OF Matrix Multiplication

Posted By: Harvey Evans     Category: C Programming     Views: 12660

## Code for PROGRAM OF Matrix Multiplication in C Programming

```#include<stdio.h>

int **mat1,**mat2,**ans;
int *ival,*jval,*kval;
void *work(void *);
main()
{
int i,j,m,k;

ival=(int *)malloc(sizeof(int)*(s_mat1*s_mat1*s_mat1));
jval=(int *)malloc(sizeof(int)*(s_mat1*s_mat1*s_mat1));
kval=(int *)malloc(sizeof(int)*(s_mat1*s_mat1*s_mat1));

printf("Enter The Size of First Matrix");
scanf("%d",&s_mat1);
printf("Enter The Size of Second matrix");
scanf("%d",&s_mat2);
mat1=(int **)malloc(sizeof(int)*s_mat1);
for(i=0;i<s_mat1;i++)
{
mat1[i]=(int *)malloc(sizeof(int)*s_mat1);
}
mat2=(int **)malloc(sizeof(int)*s_mat2);
for(i=0;i<s_mat2;i++)
{
mat2[i]=(int *)malloc(sizeof(int)*s_mat2);
}

ans=(int **)malloc(sizeof(int)*s_mat1);
for(i=0;i<s_mat1;i++)
{
ans[i]=(int *)malloc(sizeof(int)*s_mat1);
}
printf("\nEnter The Element for the Matrdix 1");
for(i=0;i<s_mat1;i++)
{
for(j=0;j<s_mat1;j++)
{
scanf("%d",&mat1[i][j]);
}
}
printf("\nEnter the Element for the Matrix 2:");

for(i=0;i<s_mat2;i++)
{
for(j=0;j<s_mat2;j++)
{
scanf("%d",&mat2[i][j]);
}
}
printf("Matrix 1\n");
for(i=0;i<s_mat1;i++)
{
for(j=0;j<s_mat1;j++)
{
printf("%d\t",mat1[i][j]);
}
printf("\n");
}
printf("Matrix 2\n");
for(i=0;i<s_mat2;i++)
{
for(j=0;j<s_mat2;j++)
{
printf("%d\t",mat2[i][j]);
}
printf("\n");
}

printf("OK");
m=0;
for(i=0;i<s_mat1;i++)
{
for(j=0;j<s_mat1;j++)
{
for(k=0;k<s_mat1;k++)
{
ival[m]=i;
jval[m]=j;
kval[m]=k;
m=m+1;
}
}
}

printf("\n\n");
{
{
continue;
}
else
{
}
}
for(i=0;i<s_mat2;i++)
{
for(j=0;j<s_mat2;j++)
{
printf("%d\t",ans[i][j]);
}
}
}
void *work(void *i)
{
int *tid;
int ind1,ind2,ind3,k,j;
int **res;
tid=(int *)i;

printf("TID:%d",*tid);
res=(int**)malloc(sizeof(int)*s_mat1);
for(j=0;j<s_mat1;j++)
{
res[j]=(int *)malloc(sizeof(int)*s_mat1);
}

{
ind1=ival[j];
ind2=jval[j];
ind3=kval[j];
res[ind1][ind2]+=mat1[ind1][ind3]*mat2[ind3][ind2];
}
for(k=0;k<s_mat1;k++)
{
for(j=0;j<s_mat1;j++)
{
ans[k][j]=ans[k][j]+res[k][j];
}
}
}
```
Share:

Didn't find what you were looking for? Find more on PROGRAM OF Matrix Multiplication Or get search suggestion and latest updates.

 Harvey Evans author of PROGRAM OF Matrix Multiplication is from London, United Kingdom. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!