Search:

Submit Article

# PROGRAM FOR ARRAY VECTOR MULTIPLICATION

Posted By: Emily Campbell     Category: C Programming     Views: 5622

## Code for PROGRAM FOR ARRAY VECTOR MULTIPLICATION in C Programming

```#include<stdio.h>

main()
{
int a1[5][5],a2[5][5],x[10],y[10],i,j,n,id;
int *semid,**result;
int np,mmax,shmid,shmid1;
int m=0;

printf("Enter the limit : ");
scanf("%d",&n);

printf("Enter the elements of arr1 :\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("a[%d][%d] : ",i,j);
scanf("%d",&a1[i][j]);
}
}

printf("Enter the elements of arr2 :\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("a[%d][%d] : ",i,j);
scanf("%d",&a2[i][j]);
}
}

printf("Enter the no.of proc. : ");
scanf("%d",&np);

result=(int **)shared(20,&shmid);
semid=(int *)shared(40,&shmid1);

for(i=0;i<n;i++)
lock_init(&semid[i]);

for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
x[m]=i;
y[m]=j;
m++;
}
}
mmax=m-1;

id=p_fork(np);
for(m=id;m<=mmax;m+=np)
{
i=x[m];
j=y[m];

locksem(&semid[i]);
result[i][j]+=a1[i][j] * a2[i][j];
unlock(&semid[i]);

}
p_join(np,id);

for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%d\t",result[i][j]);
printf("\n");
}
}
```
Share:

Didn't find what you were looking for? Find more on PROGRAM FOR ARRAY VECTOR MULTIPLICATION Or get search suggestion and latest updates.

 Emily Campbell author of PROGRAM FOR ARRAY VECTOR MULTIPLICATION is from Toronto, Canada. 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!