Write in C Program....
Write a multi-threaded program that calculates various statistical values for a list of numbers. This program will be passed a series of numbers on the command line and will then create three separate 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 81 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 these values, and the parent thread will output the values once the workers have exited.
Note:
main.c
/*
Write a program in c multi-threaded program that calculates various statistical
values for a list of numbers. This program will be passed a series
of numbers on the command line and will then create
three separate worker threads.
*/
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
int arr[50], i;
int n;
/*
average, minimum, and maximum
values will be stored globally
*/
float average;
int minimum;
int maximum;
//thread1 for calculating average
void *th()
{
int sum=0;
for(i=1;i<=n;i++)
sum=sum+arr[i];
average=sum/n;
}
//thread2 for calculating minimum value
void *th1()
{
minimum=arr[1];
for(int i=1;i<n;i++)
if(minimum>arr[i])
minimum=arr[i];
}
//thread3 for calculating maximum value
void *th2()
{
maximum=arr[1];
for(int i=1;i<=n;i++)
if(maximum<arr[i])
maximum=arr[i];
}
int main(int argc, char *argv[])
{
int count =0;
/*
a series of numbers on the command line is passing
*/
for (int i = 1; i < argc; i++)
{
arr[i] = atoi(argv[i]);
count++;
}
n = count;
printf("%d command line arguement are passed \n", count);
for(int i=1; i<=n; i++)
printf("%d\t",arr[i]);
printf("\n\n");
int t,i;
//three objectof worker threads are t1 ,t2 and t3
pthread_t t1;
pthread_t t2;
pthread_t t3;
//creating threads
t=pthread_create(&t1,NULL,&th,NULL);
pthread_join(t1,NULL);
t=pthread_create(&t2,NULL,&th1,NULL);
pthread_join(t2,NULL);
t=pthread_create(&t3,NULL,&th2,NULL);
pthread_join(t3,NULL);
/*main is the parent thread.
the parent thread will output the values
once the workers have exited.
*/
printf("The average value is %f",average);
printf("\nThe Minimum value is %d",minimum);
printf("\nThe Maximum value is %d",maximum);
return 0;
}
OUTPUT:
command line arguements:

After insert the command line arguements :

Write in C Program.... Write a multi-threaded program that calculates various statistical values for a list...
For the following multithreaded program, use system level scope for thread scheduling. Submit your program and screenshot of output in a single word/pdf file. Write a multithreaded program (USING C PROGRAM) that calculates various statistical values for a list of numbers. This program will be passed a series of numbers on the command line and will then create three separate worker threads. One thread will determine the average of the numbers, the second will determine the maximum value, and the...
Multi-threaded programming help!!! Can anyone solve this
problem? It has to be written in C, runs on Linux.
his time you need to rewrite a multithreaded Pthread program that works with sleep() or pthread_join() in order to print out Fibonacci sequences properly. Create a folder name, WK6 on your class Linux machine when you work. gcc assignment3.c-Wall -Werror -pthread You are required to develop your own program using C with the following information Need to declare a function that receives...
I want to write a C++ program which starts 2 threads. The first thread periodically generates a random number and adds it to the total. The second thread periodically generates a random number and subtracts it from the total. The main thread periodically monitors the value of the total. if the total exceeds the maximum value, the program terminates and alerts the user that the maximum has been exceeded. If the total undercuts the minimus value, the program terminates and...
C++
3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...
Write in C++ using emacs. Write a program that calculates the ending balance of several savings accounts. The program reads information about different customers’ accounts from an input file, “accounts.txt”. Each row in the file contains account information for one customer. This includes: the account number, account type (premium, choice, or basic account), starting balance, total amount deposited, and total amount withdrawn. Your program should: - open the file and check for successful open, - then calculate the ending balance...
Write a program that reads two integer values. It then calculates and displays the sum and average of all values between them, Le. if the first value is vi and the second value is 2, then the program calculates and displays the sum and average of all values in the closed range Iv1,2 Your Program must satisfy the following constraints: A. make sure that v1 is less than 2 B. Use a function named getStats(that takes two integer yalues as...
Write a Prolog program to find the maximum, minimum, and range of values in a list of numbers. Please also provide the program with output.
I need to Write a test program that prompts the user to enter 10 double values into an array, calls a method to calculate the average of the numbers, and displays the average. Next, write a method that returns the lowest value in the array and display the lowest number. The program should then prompt the user to enter 10 integer values into an array, calculates the average, and displays the average. The program should have two overloaded methods to...
Write a small JAVA program that continually reads in user values and calculates the average of all values. The program should first ask the user for the number of values to be entered. Upon storing this value, the program should proceed to read in that amount of values. What will be the best strategy here? a suggestion would be only calculating the average after you know you have read in all values. You can expect to use some type of...
Write a multi-file program for a meteorologist that calculates the wind chill factor and cloud base altitude for the inputs temperature in Fahrenheit, wind speed in mph, and the dew point in Fahrenheit. Allow the user to run the program multiple times without having to restart the program and clear the console window between sessions using system (“CLS”) which requires the cstdlib library. The program must have the following four (4) functions called from main and located in a header...