-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsPrimeNumExample.cpp
More file actions
45 lines (39 loc) · 824 Bytes
/
IsPrimeNumExample.cpp
File metadata and controls
45 lines (39 loc) · 824 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
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int n) {
if (n <= 1) {
return false;
}
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
int main() {
int n;
cout << "Daxil edeceyiniz ededlerin sayini daxil edin: ";
cin >> n;
int arr[n];
cout << "Ededleri daxil edin: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
cout << "Sade ededler: ";
for (int i = 0; i < n; i++) {
if (isPrime(arr[i])) {
cout << arr[i] << " ";
}
}
cout << endl;
cout << "Murekkeb ededler: ";
for (int i = 0; i < n; i++) {
if (!isPrime(arr[i])) {
cout << arr[i] << " ";
}
}
cout << endl;
return 0;
}