Write a program in C/C++/Linux to find the mean and then use that mean for
further calculations. Make three threads to perform different task as follows:
a) The 1st Thread will find the mean.
b) The 2nd Thread will take the mean from the 1st Thread and display the numbers
that are greater than the mean.
c) The 3rd Thread will also take the mean from the 1st Thread and display the
factorial of the two numbers that are the closest to the mean.
d) The Thread#2 and Thread#3 will wait until the thread#1 complete its task, and
then terminate by giving an appropriate message on the screen.
This program should take user input from command line as follows to calculate the mean:
Sample output is shown below:
[prompt]# ./file 12 7 11 14 5 7 9 4 33 65
Output starts here
Thread 1 starts
Mean = 16.7
Thread 1 ends
Thread 2 starts
33 65
Thread 2 ends
Thread 3 starts
12! =
14! =
Thread 3 ends
End of output
Recommended Answers
Jump to Postmy confusion is as syntax of thread creation is
pthread_create(
pthread_t *thread,
const pthread_attr_t *attr,
void *(*func)(void *),
void *arg);
how i use two arguments
int argc,char * argv[]) in itCODE TAGS!!!! Use them!
Which parameter in the
pthread_create()
call is the *argv[] parameter? Same with argc. Start …
Jump to PostWell first you can write a program containing 3 functions executed sequentially.
int main ( int argc, char *argv[] ) { calculateMean(); printGreaterThanMean(); printNearestFactorials(); }
When you can do those things, then worry about the thread issues.
All 6 Replies
sergent 52 Posting Pro
nidajaffri -1 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Salem 5,265 Posting Sage
nidajaffri -1 Newbie Poster
nidajaffri -1 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.