-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixthread1.c
More file actions
64 lines (56 loc) · 1.4 KB
/
matrixthread1.c
File metadata and controls
64 lines (56 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>
int A[10][10],B[10][10],C[10][10],m1,n1,m2,n2,i,j,k,prod;
void mult(void* arg)
{
prod = A[i][k]*B[k][j];
}
void main()
{
pthread_t id1;
printf("Enter the no of rows of first matrix");
scanf("%d",&n1);
printf("\nEnter the no of columns of first matrix");
scanf("%d",&m1);
for(i=0;i<n1;i++)
{
for(j=0;j<m1;j++)
{ printf("\nEnter element at row %d column %d",i+1,j+1);
scanf("%d",&A[i][j]);
}
}
printf("\nEnter the no of rows of second matrix");
scanf("%d",&n2);
printf("\nEnter the no of columns of second matrix");
scanf("%d",&m2);
for(i=0;i<n2;i++)
{
for(j=0;j<m2;j++)
{ printf("\nEnter element at row %d column %d",i+1,j+1);
scanf("%d",&B[i][j]);
}
}
if(m1==n2)
{
for(i=0;i<n1;i++)
for(j=0;j<m2;j++)
C[i][j]=0;
for(i=0;i<n1;i++)
for(j=0;j<m2;j++)
for(k=0;k<n2;k++)
{
pthread_create(&id1,NULL,mult,NULL);
pthread_join(id1,NULL);
C[i][j]+=prod;
}
}
else
printf("invalid");
for(i=0;i<n1;i++)
{
printf("\n");
for(j=0;j<m2;j++)
printf("%d ",C[i][j]);
}
}