Write a multithreaded program (in c language) that calculates various statistica
ID: 3808175 • Letter: W
Question
Write a multithreaded program (in c language) that calculates various statistical value for a list of numbers. This progam will be passed a series of numbers on the command line and will then create three separete worker threads. One thread will determine the average of the numbers, the second will determine the maximum value, and the third will determine the minimum value. For example, suppose your program is passed the integers 90 80 78 95 79 72 85
The program will report
The average value is 82
The minimum value is 72
The maximum value is 95
The variables representing the average, minimum and maximum values will be stored globally. The worker threads will set this values and the parent thread will output the values once the workers have exited.
Explanation / Answer
#include<stdio.h>
int main()
{
float average;
int i, n, count=0, sum=0, squaresum=0, num, min, max;
printf("Please enter the number of numbers you wish to evaluate ");
scanf_s("%d",&n);
printf("Please enter %d numbers ",n);
while(count<n)
{
min=0;
max=0;
if(num>max)
max=num;
if(num<min)
min=num;
scanf_s("%d",&num);
sum = sum+num;
squaresum = squaresum + (num*num);
count++;
}
average = 1.0*sum/n;
printf("Your average is %.2f ",average);
printf("The sum of your squares is %d ",squaresum);
printf("Your maximum number is %d ",max);
printf("Your minimum number is %d ",min);
return(0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.