-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEven.c
48 lines (45 loc) · 893 Bytes
/
Even.c
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
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<unistd.h>
#define NUM_THREADS 9
void *EVEN_NUMBERS(void *num)
{
int *n=(int*)num;
for(int i=0;i<NUM_THREADS;i++)
{
if(n[i]%2==0)
{
printf("Even Number are%d:",n[i]);
}
printf("\n");
}
pthread_exit(NULL);
}
void *ODD_NUMBERS(void *num)
{
int *arr=(int*)num;
for(int i=0;i<NUM_THREADS;i++)
{
if(arr[i]%2!=0)
{
printf("ODD Number are%d:\n",arr[i]);
}
printf("\n");
}
pthread_exit(NULL);
}
int main(int argc,char *argv[])
{
int *array=(int*)malloc((argc-1)*sizeof(int));
pthread_t pid,pid2;
for(int i=0;i<argc-1;i++)
{
array[i]=atoi(argv[i]);
}
pthread_create(&pid,NULL,EVEN_NUMBERS,(void*)array);
pthread_join(pid,(void*)array);
pthread_create(&pid2,NULL,ODD_NUMBERS,(void*)array);
pthread_join(pid2,(void*)array);
pthread_exit(NULL);
}