SlideShare a Scribd company logo
1 of 11
Download to read offline
Part 1)
#include
#include
#include
#include
/*Error handling for pthread_create and pthread_join*/
/*from the pthread_create man page*/
#define handle_error_en(en, msg) 
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
/* # of running threads */
volatile int running_threads = 0;
pthread_t thread[3]; /*Descriptors for our 3 threads*/
int numOfElements;/*Total # of elements from the user*/
struct Results{ /*Struct to hold the statistical results*/
int min;
int max;
int average;
}Results;
/*This function finds the minimum element of an array*/
void *findMin(void *array_ptr){
int i; /*counter*/
int *elements = (int*)array_ptr; /*re reference void array pointer*/
Results.min = elements[0]; /*set minimum to first element */
for(i = 0; i < numOfElements; i++){ /*iterate through array*/
if(elements[i] < Results.min){ /*if the current element is less than the current min*/
Results.min = elements[i]; /*store the new min*/
}
}
running_threads -= 1; /*Decrement thread count*/
return NULL;
}
/*This function finds the maximum element of an array*/
void *findMax(void *array_ptr){
int i; /*counter*/
int *elements = (int*)array_ptr; /*re reference void array pointer*/
for(i = 0; i < numOfElements; i++){ /*iterate through array*/
if(elements[i] > Results.max){ /*store the new max*/
Results.max = elements[i];
}
}
running_threads -= 1; /*Decrement thread count*/
return NULL;
}
/*This function finds the average of an array*/
void *findAverage(void *array_ptr){
int i; /*counter*/
int *elements = (int*)array_ptr; /*re reference void array pointer*/
for(i = 0; i < numOfElements; i++){ /*iterate through array*/
Results.average += elements[i]; /*add element @ i to average*/
}
Results.average = Results.average/numOfElements; /*Divide the sum by the number of
elements*/
running_threads -= 1; /*Decrement running threads counter*/
return NULL;
}
/* This method accepts a int n(initial size of array) and
pointer to an array and returns # of elements in the array
*/
int getArrayInput(int n, int *array_ptr){
int input;/*Store user input */
int numberOfElements = 0;/*Number of Integers inputed*/
printf("Creating Dynamic Array... - ");
for(;;){ /*infinite loop*/
printf("Enter a positive value: Negative Number to Stop - ");
//Get Int from console, store at address of input
if (scanf("%d",&input) != 1){
printf(" Oops that wasn't an Integer lets try filling the array again Remember
INTEGERS only! ");
exit(EXIT_FAILURE);
}
if (input >= 0){
if (numberOfElements == n){
n += 1; //Make room for the current input
array_ptr = realloc(array_ptr, n * sizeof(int));//realloc array and set pointer
}
array_ptr[numberOfElements++] = input;//Store input at next empty element
} else {
printf(" Number of Integers: %d ", numberOfElements);
break;
}
}
return numberOfElements;
}
/*This function joins our n number of threads */
void joinThreads(int numberOfThreads){
int i; /*count*/
int s; /*error #*/
while(numberOfThreads >= 0){ /*Join our threads*/
s = pthread_join(thread[numberOfThreads], NULL);
/*if we recieve anything other than 0 we have a join error*/
if (s != 0){
/*handle error*/
handle_error_en(s, "pthread_create");
}
numberOfThreads--;
}
}
/*This function creates the 3 threads we need and supplys
error catching for pthread_create, it could be
modified easily to create any # of threads automatically
*/
void createThreads(int *array_ptr){
int s; /*error #*/
/*Create a thread and passing in the function to begin
exectuing as well as that functions required arguments*/
s = pthread_create(&thread[0], NULL, findMin, (void *)array_ptr);
if (s != 0){
handle_error_en(s, "pthread_create");
}
running_threads += 1;
/*Create a thread and passing in the function to begin
exectuing as well as that functions required arguments*/
s = pthread_create(&thread[1], NULL, findMax, (void *)array_ptr);
if (s != 0){
handle_error_en(s, "pthread_create");
}
running_threads += 1;
/*Create a thread and passing in the function to begin
exectuing as well as that functions required arguments*/
s = pthread_create(&thread[2], NULL, findAverage, (void *)array_ptr);
if (s != 0){
handle_error_en(s, "pthread_create");
}
running_threads += 1;
}
/* The main function initialiazes the dynamic array as well
as allocating space for it, Then it creates, using pthread_create,
3 Threads 1 to calculate the min, the max, and the average.
We then wait until each thread completes its task and then
join the 3 threads and prompt the user with the results
*/
int main(){
int n = 1; /* Initial Array Size*/
int *array_ptr = malloc(n * sizeof(int));/*Initialize array pointer*/
/*get an n sized array of elements from the user and save count*/
numOfElements = getArrayInput(n, array_ptr);
createThreads(array_ptr);
while(running_threads>0){ /*Wait for each thread to decrement*/
sleep(1);
}
joinThreads(2); /*Call our thread joining function passing # of threads */
/*Prompt the user with our results*/
printf(" The average is %d The maximum is %d The minimum is %d ",Results.average,
Results.max, Results.min);
return(0);
}
Solution
Part 1)
#include
#include
#include
#include
/*Error handling for pthread_create and pthread_join*/
/*from the pthread_create man page*/
#define handle_error_en(en, msg) 
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
/* # of running threads */
volatile int running_threads = 0;
pthread_t thread[3]; /*Descriptors for our 3 threads*/
int numOfElements;/*Total # of elements from the user*/
struct Results{ /*Struct to hold the statistical results*/
int min;
int max;
int average;
}Results;
/*This function finds the minimum element of an array*/
void *findMin(void *array_ptr){
int i; /*counter*/
int *elements = (int*)array_ptr; /*re reference void array pointer*/
Results.min = elements[0]; /*set minimum to first element */
for(i = 0; i < numOfElements; i++){ /*iterate through array*/
if(elements[i] < Results.min){ /*if the current element is less than the current min*/
Results.min = elements[i]; /*store the new min*/
}
}
running_threads -= 1; /*Decrement thread count*/
return NULL;
}
/*This function finds the maximum element of an array*/
void *findMax(void *array_ptr){
int i; /*counter*/
int *elements = (int*)array_ptr; /*re reference void array pointer*/
for(i = 0; i < numOfElements; i++){ /*iterate through array*/
if(elements[i] > Results.max){ /*store the new max*/
Results.max = elements[i];
}
}
running_threads -= 1; /*Decrement thread count*/
return NULL;
}
/*This function finds the average of an array*/
void *findAverage(void *array_ptr){
int i; /*counter*/
int *elements = (int*)array_ptr; /*re reference void array pointer*/
for(i = 0; i < numOfElements; i++){ /*iterate through array*/
Results.average += elements[i]; /*add element @ i to average*/
}
Results.average = Results.average/numOfElements; /*Divide the sum by the number of
elements*/
running_threads -= 1; /*Decrement running threads counter*/
return NULL;
}
/* This method accepts a int n(initial size of array) and
pointer to an array and returns # of elements in the array
*/
int getArrayInput(int n, int *array_ptr){
int input;/*Store user input */
int numberOfElements = 0;/*Number of Integers inputed*/
printf("Creating Dynamic Array... - ");
for(;;){ /*infinite loop*/
printf("Enter a positive value: Negative Number to Stop - ");
//Get Int from console, store at address of input
if (scanf("%d",&input) != 1){
printf(" Oops that wasn't an Integer lets try filling the array again Remember
INTEGERS only! ");
exit(EXIT_FAILURE);
}
if (input >= 0){
if (numberOfElements == n){
n += 1; //Make room for the current input
array_ptr = realloc(array_ptr, n * sizeof(int));//realloc array and set pointer
}
array_ptr[numberOfElements++] = input;//Store input at next empty element
} else {
printf(" Number of Integers: %d ", numberOfElements);
break;
}
}
return numberOfElements;
}
/*This function joins our n number of threads */
void joinThreads(int numberOfThreads){
int i; /*count*/
int s; /*error #*/
while(numberOfThreads >= 0){ /*Join our threads*/
s = pthread_join(thread[numberOfThreads], NULL);
/*if we recieve anything other than 0 we have a join error*/
if (s != 0){
/*handle error*/
handle_error_en(s, "pthread_create");
}
numberOfThreads--;
}
}
/*This function creates the 3 threads we need and supplys
error catching for pthread_create, it could be
modified easily to create any # of threads automatically
*/
void createThreads(int *array_ptr){
int s; /*error #*/
/*Create a thread and passing in the function to begin
exectuing as well as that functions required arguments*/
s = pthread_create(&thread[0], NULL, findMin, (void *)array_ptr);
if (s != 0){
handle_error_en(s, "pthread_create");
}
running_threads += 1;
/*Create a thread and passing in the function to begin
exectuing as well as that functions required arguments*/
s = pthread_create(&thread[1], NULL, findMax, (void *)array_ptr);
if (s != 0){
handle_error_en(s, "pthread_create");
}
running_threads += 1;
/*Create a thread and passing in the function to begin
exectuing as well as that functions required arguments*/
s = pthread_create(&thread[2], NULL, findAverage, (void *)array_ptr);
if (s != 0){
handle_error_en(s, "pthread_create");
}
running_threads += 1;
}
/* The main function initialiazes the dynamic array as well
as allocating space for it, Then it creates, using pthread_create,
3 Threads 1 to calculate the min, the max, and the average.
We then wait until each thread completes its task and then
join the 3 threads and prompt the user with the results
*/
int main(){
int n = 1; /* Initial Array Size*/
int *array_ptr = malloc(n * sizeof(int));/*Initialize array pointer*/
/*get an n sized array of elements from the user and save count*/
numOfElements = getArrayInput(n, array_ptr);
createThreads(array_ptr);
while(running_threads>0){ /*Wait for each thread to decrement*/
sleep(1);
}
joinThreads(2); /*Call our thread joining function passing # of threads */
/*Prompt the user with our results*/
printf(" The average is %d The maximum is %d The minimum is %d ",Results.average,
Results.max, Results.min);
return(0);
}

More Related Content

Similar to Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf

Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfarri2009av
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
 
I need help with the 2nd TODO comment and the other comments Ill.pdf
I need help with the 2nd TODO comment and the other comments Ill.pdfI need help with the 2nd TODO comment and the other comments Ill.pdf
I need help with the 2nd TODO comment and the other comments Ill.pdfEye2eyeopticians10
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfaptcomputerzone
 
import java.util.Scanner;public class ArrayData {      AR.pdf
import java.util.Scanner;public class ArrayData {        AR.pdfimport java.util.Scanner;public class ArrayData {        AR.pdf
import java.util.Scanner;public class ArrayData {      AR.pdfinfo382133
 
Operator overloading in c++ is the most required.
Operator overloading in c++ is the most required.Operator overloading in c++ is the most required.
Operator overloading in c++ is the most required.iammukesh1075
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfarorasales234
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdfakkhan101
 
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfMerge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfmdameer02
 
MinOfFourNumbers.javaimport java.util.Scanner;public class MinOf.pdf
MinOfFourNumbers.javaimport java.util.Scanner;public class MinOf.pdfMinOfFourNumbers.javaimport java.util.Scanner;public class MinOf.pdf
MinOfFourNumbers.javaimport java.util.Scanner;public class MinOf.pdfaptex1
 
This class maintains a list of 4 integers. This list .docx
 This class maintains a list of 4 integers.   This list .docx This class maintains a list of 4 integers.   This list .docx
This class maintains a list of 4 integers. This list .docxKomlin1
 
I have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdfI have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdffasttrackscardecors
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfaquazac
 

Similar to Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf (20)

Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
I need help with the 2nd TODO comment and the other comments Ill.pdf
I need help with the 2nd TODO comment and the other comments Ill.pdfI need help with the 2nd TODO comment and the other comments Ill.pdf
I need help with the 2nd TODO comment and the other comments Ill.pdf
 
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
 
import java.util.Scanner;public class ArrayData {      AR.pdf
import java.util.Scanner;public class ArrayData {        AR.pdfimport java.util.Scanner;public class ArrayData {        AR.pdf
import java.util.Scanner;public class ArrayData {      AR.pdf
 
Operator overloading in c++ is the most required.
Operator overloading in c++ is the most required.Operator overloading in c++ is the most required.
Operator overloading in c++ is the most required.
 
lecture12.ppt
lecture12.pptlecture12.ppt
lecture12.ppt
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdf
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfMerge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
 
MinOfFourNumbers.javaimport java.util.Scanner;public class MinOf.pdf
MinOfFourNumbers.javaimport java.util.Scanner;public class MinOf.pdfMinOfFourNumbers.javaimport java.util.Scanner;public class MinOf.pdf
MinOfFourNumbers.javaimport java.util.Scanner;public class MinOf.pdf
 
This class maintains a list of 4 integers. This list .docx
 This class maintains a list of 4 integers.   This list .docx This class maintains a list of 4 integers.   This list .docx
This class maintains a list of 4 integers. This list .docx
 
I have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdfI have C++ question that I do not know how to do, Can you teach me t.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdf
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
Chp4(ref dynamic)
Chp4(ref dynamic)Chp4(ref dynamic)
Chp4(ref dynamic)
 

More from mohammadirfan136964

2. Ligamentum arteriosumThe aortic arch loops over the left pulmo.pdf
2. Ligamentum arteriosumThe aortic arch loops over the left pulmo.pdf2. Ligamentum arteriosumThe aortic arch loops over the left pulmo.pdf
2. Ligamentum arteriosumThe aortic arch loops over the left pulmo.pdfmohammadirfan136964
 
moles should be equal to complete consumption so.pdf
                     moles should be equal to complete consumption  so.pdf                     moles should be equal to complete consumption  so.pdf
moles should be equal to complete consumption so.pdfmohammadirfan136964
 
TrueOne of the fundamental rules which control the PLSS system is .pdf
TrueOne of the fundamental rules which control the PLSS system is .pdfTrueOne of the fundamental rules which control the PLSS system is .pdf
TrueOne of the fundamental rules which control the PLSS system is .pdfmohammadirfan136964
 
The stronger the attractions betweenparticles (mo.pdf
                     The stronger the attractions betweenparticles (mo.pdf                     The stronger the attractions betweenparticles (mo.pdf
The stronger the attractions betweenparticles (mo.pdfmohammadirfan136964
 
a. It gives benzalacetone b. acetone will underg.pdf
                     a. It gives benzalacetone  b. acetone will underg.pdf                     a. It gives benzalacetone  b. acetone will underg.pdf
a. It gives benzalacetone b. acetone will underg.pdfmohammadirfan136964
 
what is the mean, median, mode and the midrange for 191, 167,257,1.pdf
what is the mean, median, mode and the midrange for  191, 167,257,1.pdfwhat is the mean, median, mode and the midrange for  191, 167,257,1.pdf
what is the mean, median, mode and the midrange for 191, 167,257,1.pdfmohammadirfan136964
 
Disodium malonate is an ionic sodium salt that is soluble in water..pdf
Disodium malonate is an ionic sodium salt that is soluble in water..pdfDisodium malonate is an ionic sodium salt that is soluble in water..pdf
Disodium malonate is an ionic sodium salt that is soluble in water..pdfmohammadirfan136964
 
They showed that GFP protein could be expressed in the organisms wit.pdf
They showed that GFP protein could be expressed in the organisms wit.pdfThey showed that GFP protein could be expressed in the organisms wit.pdf
They showed that GFP protein could be expressed in the organisms wit.pdfmohammadirfan136964
 
Thepossible mechanism by which a 75kD nuclear protein is imported in.pdf
Thepossible mechanism by which a 75kD nuclear protein is imported in.pdfThepossible mechanism by which a 75kD nuclear protein is imported in.pdf
Thepossible mechanism by which a 75kD nuclear protein is imported in.pdfmohammadirfan136964
 
The neurons are nervous cells which play the central role in generat.pdf
The neurons are nervous cells which play the central role in generat.pdfThe neurons are nervous cells which play the central role in generat.pdf
The neurons are nervous cells which play the central role in generat.pdfmohammadirfan136964
 
The parts of the respiratory tract which have nonkeratinized stratif.pdf
The parts of the respiratory tract which have nonkeratinized stratif.pdfThe parts of the respiratory tract which have nonkeratinized stratif.pdf
The parts of the respiratory tract which have nonkeratinized stratif.pdfmohammadirfan136964
 
The impact of Brexit would be visible on the financial instituations.pdf
The impact of Brexit would be visible on the financial instituations.pdfThe impact of Brexit would be visible on the financial instituations.pdf
The impact of Brexit would be visible on the financial instituations.pdfmohammadirfan136964
 
The alkaline earth metals burn in oxygen to form the monoxide, MO wh.pdf
The alkaline earth metals burn in oxygen to form the monoxide, MO wh.pdfThe alkaline earth metals burn in oxygen to form the monoxide, MO wh.pdf
The alkaline earth metals burn in oxygen to form the monoxide, MO wh.pdfmohammadirfan136964
 
Squid molluscCrab ArthropodsCrayfish ArthropodsPolychaete .pdf
Squid molluscCrab ArthropodsCrayfish ArthropodsPolychaete .pdfSquid molluscCrab ArthropodsCrayfish ArthropodsPolychaete .pdf
Squid molluscCrab ArthropodsCrayfish ArthropodsPolychaete .pdfmohammadirfan136964
 
The code you written is little bit confusing and lengthy. Here is th.pdf
The code you written is little bit confusing and lengthy. Here is th.pdfThe code you written is little bit confusing and lengthy. Here is th.pdf
The code you written is little bit confusing and lengthy. Here is th.pdfmohammadirfan136964
 
Ques-1Normala flora and microbiota of nose and mouth are non-infe.pdf
Ques-1Normala flora and microbiota of nose and mouth are non-infe.pdfQues-1Normala flora and microbiota of nose and mouth are non-infe.pdf
Ques-1Normala flora and microbiota of nose and mouth are non-infe.pdfmohammadirfan136964
 
Solution.According to IASB framework INCOME is the one of element .pdf
Solution.According to IASB framework INCOME is the one of element .pdfSolution.According to IASB framework INCOME is the one of element .pdf
Solution.According to IASB framework INCOME is the one of element .pdfmohammadirfan136964
 
7. Answer is A.Cytochromes are protien containing iron or heme gro.pdf
7. Answer is A.Cytochromes are protien containing iron or heme gro.pdf7. Answer is A.Cytochromes are protien containing iron or heme gro.pdf
7. Answer is A.Cytochromes are protien containing iron or heme gro.pdfmohammadirfan136964
 
A and C. RGB analog component video uses no compression, imposes no .pdf
A and C. RGB analog component video uses no compression, imposes no .pdfA and C. RGB analog component video uses no compression, imposes no .pdf
A and C. RGB analog component video uses no compression, imposes no .pdfmohammadirfan136964
 
Public key authentication is the most secure colution and utilizes a.pdf
Public key authentication is the most secure colution and utilizes a.pdfPublic key authentication is the most secure colution and utilizes a.pdf
Public key authentication is the most secure colution and utilizes a.pdfmohammadirfan136964
 

More from mohammadirfan136964 (20)

2. Ligamentum arteriosumThe aortic arch loops over the left pulmo.pdf
2. Ligamentum arteriosumThe aortic arch loops over the left pulmo.pdf2. Ligamentum arteriosumThe aortic arch loops over the left pulmo.pdf
2. Ligamentum arteriosumThe aortic arch loops over the left pulmo.pdf
 
moles should be equal to complete consumption so.pdf
                     moles should be equal to complete consumption  so.pdf                     moles should be equal to complete consumption  so.pdf
moles should be equal to complete consumption so.pdf
 
TrueOne of the fundamental rules which control the PLSS system is .pdf
TrueOne of the fundamental rules which control the PLSS system is .pdfTrueOne of the fundamental rules which control the PLSS system is .pdf
TrueOne of the fundamental rules which control the PLSS system is .pdf
 
The stronger the attractions betweenparticles (mo.pdf
                     The stronger the attractions betweenparticles (mo.pdf                     The stronger the attractions betweenparticles (mo.pdf
The stronger the attractions betweenparticles (mo.pdf
 
a. It gives benzalacetone b. acetone will underg.pdf
                     a. It gives benzalacetone  b. acetone will underg.pdf                     a. It gives benzalacetone  b. acetone will underg.pdf
a. It gives benzalacetone b. acetone will underg.pdf
 
what is the mean, median, mode and the midrange for 191, 167,257,1.pdf
what is the mean, median, mode and the midrange for  191, 167,257,1.pdfwhat is the mean, median, mode and the midrange for  191, 167,257,1.pdf
what is the mean, median, mode and the midrange for 191, 167,257,1.pdf
 
Disodium malonate is an ionic sodium salt that is soluble in water..pdf
Disodium malonate is an ionic sodium salt that is soluble in water..pdfDisodium malonate is an ionic sodium salt that is soluble in water..pdf
Disodium malonate is an ionic sodium salt that is soluble in water..pdf
 
They showed that GFP protein could be expressed in the organisms wit.pdf
They showed that GFP protein could be expressed in the organisms wit.pdfThey showed that GFP protein could be expressed in the organisms wit.pdf
They showed that GFP protein could be expressed in the organisms wit.pdf
 
Thepossible mechanism by which a 75kD nuclear protein is imported in.pdf
Thepossible mechanism by which a 75kD nuclear protein is imported in.pdfThepossible mechanism by which a 75kD nuclear protein is imported in.pdf
Thepossible mechanism by which a 75kD nuclear protein is imported in.pdf
 
The neurons are nervous cells which play the central role in generat.pdf
The neurons are nervous cells which play the central role in generat.pdfThe neurons are nervous cells which play the central role in generat.pdf
The neurons are nervous cells which play the central role in generat.pdf
 
The parts of the respiratory tract which have nonkeratinized stratif.pdf
The parts of the respiratory tract which have nonkeratinized stratif.pdfThe parts of the respiratory tract which have nonkeratinized stratif.pdf
The parts of the respiratory tract which have nonkeratinized stratif.pdf
 
The impact of Brexit would be visible on the financial instituations.pdf
The impact of Brexit would be visible on the financial instituations.pdfThe impact of Brexit would be visible on the financial instituations.pdf
The impact of Brexit would be visible on the financial instituations.pdf
 
The alkaline earth metals burn in oxygen to form the monoxide, MO wh.pdf
The alkaline earth metals burn in oxygen to form the monoxide, MO wh.pdfThe alkaline earth metals burn in oxygen to form the monoxide, MO wh.pdf
The alkaline earth metals burn in oxygen to form the monoxide, MO wh.pdf
 
Squid molluscCrab ArthropodsCrayfish ArthropodsPolychaete .pdf
Squid molluscCrab ArthropodsCrayfish ArthropodsPolychaete .pdfSquid molluscCrab ArthropodsCrayfish ArthropodsPolychaete .pdf
Squid molluscCrab ArthropodsCrayfish ArthropodsPolychaete .pdf
 
The code you written is little bit confusing and lengthy. Here is th.pdf
The code you written is little bit confusing and lengthy. Here is th.pdfThe code you written is little bit confusing and lengthy. Here is th.pdf
The code you written is little bit confusing and lengthy. Here is th.pdf
 
Ques-1Normala flora and microbiota of nose and mouth are non-infe.pdf
Ques-1Normala flora and microbiota of nose and mouth are non-infe.pdfQues-1Normala flora and microbiota of nose and mouth are non-infe.pdf
Ques-1Normala flora and microbiota of nose and mouth are non-infe.pdf
 
Solution.According to IASB framework INCOME is the one of element .pdf
Solution.According to IASB framework INCOME is the one of element .pdfSolution.According to IASB framework INCOME is the one of element .pdf
Solution.According to IASB framework INCOME is the one of element .pdf
 
7. Answer is A.Cytochromes are protien containing iron or heme gro.pdf
7. Answer is A.Cytochromes are protien containing iron or heme gro.pdf7. Answer is A.Cytochromes are protien containing iron or heme gro.pdf
7. Answer is A.Cytochromes are protien containing iron or heme gro.pdf
 
A and C. RGB analog component video uses no compression, imposes no .pdf
A and C. RGB analog component video uses no compression, imposes no .pdfA and C. RGB analog component video uses no compression, imposes no .pdf
A and C. RGB analog component video uses no compression, imposes no .pdf
 
Public key authentication is the most secure colution and utilizes a.pdf
Public key authentication is the most secure colution and utilizes a.pdfPublic key authentication is the most secure colution and utilizes a.pdf
Public key authentication is the most secure colution and utilizes a.pdf
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 

Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf

  • 1. Part 1) #include #include #include #include /*Error handling for pthread_create and pthread_join*/ /*from the pthread_create man page*/ #define handle_error_en(en, msg) do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) /* # of running threads */ volatile int running_threads = 0; pthread_t thread[3]; /*Descriptors for our 3 threads*/ int numOfElements;/*Total # of elements from the user*/ struct Results{ /*Struct to hold the statistical results*/ int min; int max; int average; }Results; /*This function finds the minimum element of an array*/ void *findMin(void *array_ptr){ int i; /*counter*/ int *elements = (int*)array_ptr; /*re reference void array pointer*/ Results.min = elements[0]; /*set minimum to first element */ for(i = 0; i < numOfElements; i++){ /*iterate through array*/ if(elements[i] < Results.min){ /*if the current element is less than the current min*/ Results.min = elements[i]; /*store the new min*/ } } running_threads -= 1; /*Decrement thread count*/ return NULL;
  • 2. } /*This function finds the maximum element of an array*/ void *findMax(void *array_ptr){ int i; /*counter*/ int *elements = (int*)array_ptr; /*re reference void array pointer*/ for(i = 0; i < numOfElements; i++){ /*iterate through array*/ if(elements[i] > Results.max){ /*store the new max*/ Results.max = elements[i]; } } running_threads -= 1; /*Decrement thread count*/ return NULL; } /*This function finds the average of an array*/ void *findAverage(void *array_ptr){ int i; /*counter*/ int *elements = (int*)array_ptr; /*re reference void array pointer*/ for(i = 0; i < numOfElements; i++){ /*iterate through array*/ Results.average += elements[i]; /*add element @ i to average*/ } Results.average = Results.average/numOfElements; /*Divide the sum by the number of elements*/ running_threads -= 1; /*Decrement running threads counter*/ return NULL; } /* This method accepts a int n(initial size of array) and pointer to an array and returns # of elements in the array */ int getArrayInput(int n, int *array_ptr){ int input;/*Store user input */ int numberOfElements = 0;/*Number of Integers inputed*/ printf("Creating Dynamic Array... - ");
  • 3. for(;;){ /*infinite loop*/ printf("Enter a positive value: Negative Number to Stop - "); //Get Int from console, store at address of input if (scanf("%d",&input) != 1){ printf(" Oops that wasn't an Integer lets try filling the array again Remember INTEGERS only! "); exit(EXIT_FAILURE); } if (input >= 0){ if (numberOfElements == n){ n += 1; //Make room for the current input array_ptr = realloc(array_ptr, n * sizeof(int));//realloc array and set pointer } array_ptr[numberOfElements++] = input;//Store input at next empty element } else { printf(" Number of Integers: %d ", numberOfElements); break; } } return numberOfElements; } /*This function joins our n number of threads */ void joinThreads(int numberOfThreads){ int i; /*count*/ int s; /*error #*/ while(numberOfThreads >= 0){ /*Join our threads*/ s = pthread_join(thread[numberOfThreads], NULL);
  • 4. /*if we recieve anything other than 0 we have a join error*/ if (s != 0){ /*handle error*/ handle_error_en(s, "pthread_create"); } numberOfThreads--; } } /*This function creates the 3 threads we need and supplys error catching for pthread_create, it could be modified easily to create any # of threads automatically */ void createThreads(int *array_ptr){ int s; /*error #*/ /*Create a thread and passing in the function to begin exectuing as well as that functions required arguments*/ s = pthread_create(&thread[0], NULL, findMin, (void *)array_ptr); if (s != 0){ handle_error_en(s, "pthread_create"); } running_threads += 1; /*Create a thread and passing in the function to begin exectuing as well as that functions required arguments*/ s = pthread_create(&thread[1], NULL, findMax, (void *)array_ptr); if (s != 0){ handle_error_en(s, "pthread_create"); } running_threads += 1;
  • 5. /*Create a thread and passing in the function to begin exectuing as well as that functions required arguments*/ s = pthread_create(&thread[2], NULL, findAverage, (void *)array_ptr); if (s != 0){ handle_error_en(s, "pthread_create"); } running_threads += 1; } /* The main function initialiazes the dynamic array as well as allocating space for it, Then it creates, using pthread_create, 3 Threads 1 to calculate the min, the max, and the average. We then wait until each thread completes its task and then join the 3 threads and prompt the user with the results */ int main(){ int n = 1; /* Initial Array Size*/ int *array_ptr = malloc(n * sizeof(int));/*Initialize array pointer*/ /*get an n sized array of elements from the user and save count*/ numOfElements = getArrayInput(n, array_ptr); createThreads(array_ptr); while(running_threads>0){ /*Wait for each thread to decrement*/ sleep(1); } joinThreads(2); /*Call our thread joining function passing # of threads */ /*Prompt the user with our results*/ printf(" The average is %d The maximum is %d The minimum is %d ",Results.average, Results.max, Results.min); return(0); }
  • 6. Solution Part 1) #include #include #include #include /*Error handling for pthread_create and pthread_join*/ /*from the pthread_create man page*/ #define handle_error_en(en, msg) do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) /* # of running threads */ volatile int running_threads = 0; pthread_t thread[3]; /*Descriptors for our 3 threads*/ int numOfElements;/*Total # of elements from the user*/ struct Results{ /*Struct to hold the statistical results*/ int min; int max; int average; }Results; /*This function finds the minimum element of an array*/ void *findMin(void *array_ptr){ int i; /*counter*/ int *elements = (int*)array_ptr; /*re reference void array pointer*/ Results.min = elements[0]; /*set minimum to first element */ for(i = 0; i < numOfElements; i++){ /*iterate through array*/ if(elements[i] < Results.min){ /*if the current element is less than the current min*/ Results.min = elements[i]; /*store the new min*/ } }
  • 7. running_threads -= 1; /*Decrement thread count*/ return NULL; } /*This function finds the maximum element of an array*/ void *findMax(void *array_ptr){ int i; /*counter*/ int *elements = (int*)array_ptr; /*re reference void array pointer*/ for(i = 0; i < numOfElements; i++){ /*iterate through array*/ if(elements[i] > Results.max){ /*store the new max*/ Results.max = elements[i]; } } running_threads -= 1; /*Decrement thread count*/ return NULL; } /*This function finds the average of an array*/ void *findAverage(void *array_ptr){ int i; /*counter*/ int *elements = (int*)array_ptr; /*re reference void array pointer*/ for(i = 0; i < numOfElements; i++){ /*iterate through array*/ Results.average += elements[i]; /*add element @ i to average*/ } Results.average = Results.average/numOfElements; /*Divide the sum by the number of elements*/ running_threads -= 1; /*Decrement running threads counter*/ return NULL; } /* This method accepts a int n(initial size of array) and pointer to an array and returns # of elements in the array */ int getArrayInput(int n, int *array_ptr){ int input;/*Store user input */
  • 8. int numberOfElements = 0;/*Number of Integers inputed*/ printf("Creating Dynamic Array... - "); for(;;){ /*infinite loop*/ printf("Enter a positive value: Negative Number to Stop - "); //Get Int from console, store at address of input if (scanf("%d",&input) != 1){ printf(" Oops that wasn't an Integer lets try filling the array again Remember INTEGERS only! "); exit(EXIT_FAILURE); } if (input >= 0){ if (numberOfElements == n){ n += 1; //Make room for the current input array_ptr = realloc(array_ptr, n * sizeof(int));//realloc array and set pointer } array_ptr[numberOfElements++] = input;//Store input at next empty element } else { printf(" Number of Integers: %d ", numberOfElements); break; } } return numberOfElements; } /*This function joins our n number of threads */ void joinThreads(int numberOfThreads){ int i; /*count*/ int s; /*error #*/
  • 9. while(numberOfThreads >= 0){ /*Join our threads*/ s = pthread_join(thread[numberOfThreads], NULL); /*if we recieve anything other than 0 we have a join error*/ if (s != 0){ /*handle error*/ handle_error_en(s, "pthread_create"); } numberOfThreads--; } } /*This function creates the 3 threads we need and supplys error catching for pthread_create, it could be modified easily to create any # of threads automatically */ void createThreads(int *array_ptr){ int s; /*error #*/ /*Create a thread and passing in the function to begin exectuing as well as that functions required arguments*/ s = pthread_create(&thread[0], NULL, findMin, (void *)array_ptr); if (s != 0){ handle_error_en(s, "pthread_create"); } running_threads += 1; /*Create a thread and passing in the function to begin exectuing as well as that functions required arguments*/ s = pthread_create(&thread[1], NULL, findMax, (void *)array_ptr); if (s != 0){ handle_error_en(s, "pthread_create");
  • 10. } running_threads += 1; /*Create a thread and passing in the function to begin exectuing as well as that functions required arguments*/ s = pthread_create(&thread[2], NULL, findAverage, (void *)array_ptr); if (s != 0){ handle_error_en(s, "pthread_create"); } running_threads += 1; } /* The main function initialiazes the dynamic array as well as allocating space for it, Then it creates, using pthread_create, 3 Threads 1 to calculate the min, the max, and the average. We then wait until each thread completes its task and then join the 3 threads and prompt the user with the results */ int main(){ int n = 1; /* Initial Array Size*/ int *array_ptr = malloc(n * sizeof(int));/*Initialize array pointer*/ /*get an n sized array of elements from the user and save count*/ numOfElements = getArrayInput(n, array_ptr); createThreads(array_ptr); while(running_threads>0){ /*Wait for each thread to decrement*/ sleep(1); } joinThreads(2); /*Call our thread joining function passing # of threads */ /*Prompt the user with our results*/ printf(" The average is %d The maximum is %d The minimum is %d ",Results.average, Results.max, Results.min);