Search:

Submit Article

# Program to find standard deviation strdev using thread

Posted By: George Evans     Category: C Programming     Views: 6730

## Code for Program to find standard deviation strdev using thread in C Programming

```#include <stdio.h>

int a[100];
int nproc=3,N=10;
int barcount,over,count,total;
float average,final_dev;
void *work(void *arg);

main()
{
int bar,k,ctr,i,j;
void **p;

for(i=0;i<N;i++)
scanf("%d",a+i);

total=0;count=0;over=0;
final_dev=0.0;barcount=0;

for(i=0;i<nproc;i++)
{
continue;
else
}

printf("ERR1...\n");

while(barcount!=nproc) sleep(1);

count=0;average=total*1.0/N;

barcount=0;
//printf("main lock");

while(barcount!=nproc) sleep(1);

printf("The Total is %d\n",total);
printf("The Average is %f\n",average);
printf("The Standard devn is %f\n",final_dev);

}

void *work(void *arg)
{
int sum=0;
int i,id;float dev=0;void *stat;

if(over==0)
{
//            printf("lock\n");
//            printf("unlock");
}

id=(int) arg;
{
i=count;count+=5;

if(i<N)
{
int bound;
bound=(N<i+5) ? N:i+5;
for(;i<bound;i++)
sum+=a[i];
sleep(1);
}
elsebreak;

}

total+=sum;

//    printf("%d did  %d  of  %d \n",id,sum,total);

barcount++;

while(1)
{
i=count;count+=5;
if(i<N)
{
int bound;
bound=(N<i+5) ? N:i+5;
for(;i<bound;i++)
dev+=(average>a[i])?average-a[i]:a[i]-average;
sleep(1);
}
elsebreak;

}

final_dev+=dev;
barcount++;

//        printf("Therad %d did %f of %f\n",id,dev,final_dev);

}
```
Share:

Didn't find what you were looking for? Find more on Program to find standard deviation strdev using thread Or get search suggestion and latest updates.

 George Evans author of Program to find standard deviation strdev using thread 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!