-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrimenumberSorter.c
66 lines (54 loc) · 979 Bytes
/
PrimenumberSorter.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
int prime(int num)
{
int prime;
if (num < 0)
{
prime = 0;
}
else if (num == 1 || num == 0)
{
prime = 0;
}
else if (num == 3 || num == 2)
{
prime = 1;
}
else
{
for (int i = 2; num / 2 >= i; i++)
{
if (num % i == 0)
{
prime = 0;
break;
}
if (num / 2 == i)
{
prime = 1;
}
}
}
return (prime);
}
int main()
{
int size;
printf("Enter the number of elements in your array : ");
scanf("%d", &size);
int array[size];
for (int i = 0; i < size; i++)
{
printf("enter the %d element : ", i + 1);
scanf("%d", &array[i]);
}
for (int i = 0; i < size; i++)
{
if (prime(array[i]) == 1)
{
printf("%d ", array[i]);
}
}
printf("\n");
return 0;
}