-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExerc2.cpp
More file actions
55 lines (30 loc) · 762 Bytes
/
Exerc2.cpp
File metadata and controls
55 lines (30 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <pthread.h>
using namespace std;
int vetor[14]= {2423,4564,853,2243,65756,32,3455,244,346546,22,4564,2,435,457447};
float a1, a2;
pthread_t thread1, thread2;
void *firstPart (void *Arg){
int partial=0;
for (int i= 0; i<7; i++){
partial+= vetor[i];
}
a1= float(partial/7.0);
return 0;
}
void *secondPart (void *Arg){
int partial=0;
for (int i= 7; i<14; i++){
partial+= vetor[i];
}
a2= float(partial/7.0);
return 0;
}
int main(){
pthread_create(&thread1, NULL, firstPart, NULL);
pthread_create(&thread2, NULL, secondPart, NULL);
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
cout<<"Average: "<<(a1+a2)/2.0;
return 0;
}