-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.2_Prime.c
More file actions
41 lines (38 loc) · 873 Bytes
/
9.2_Prime.c
File metadata and controls
41 lines (38 loc) · 873 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
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
void* start_routine(void *);
void* pth_body(void *args)
{
int count = 0, i;
if (*((int*)args)<0)
printf("Enter a natural number\n");
else
{
for(i = 1; i <= (*(int*)args); i++)
{
if(*((int*)args) % i == 0)
count++;
if(count > 2)
break;
}
}
pthread_exit((void *) count);
}
int main()
{
pthread_t thread;
while(1)
{
int n,f;
printf("Enter a number: ");
scanf("%d", &n);
pthread_create(&thread, NULL, &pth_body, &n);
pthread_join(thread, (void *)&f);
if (f == 2)
printf("Prime Number\n");
else
printf("Not prime Number\n");
sleep(1);
}
}