Skip to content

Commit f52578c

Browse files
authored
Create 1.cpp
1 parent 06a1d38 commit f52578c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

20/1.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
// 소수 판별 함수(2이상의 자연수에 대하여)
6+
bool isPrimeNumber(int x) {
7+
// 2부터 x의 제곱근까지의 모든 수를 확인하며
8+
for (int i = 2; i <= (int) sqrt(x); i++) {
9+
// x가 해당 수로 나누어떨어진다면
10+
if (x % i == 0) {
11+
return false; // 소수가 아님
12+
}
13+
}
14+
return true; // 소수임
15+
}
16+
17+
int main() {
18+
cout << isPrimeNumber(4) << '\n';
19+
cout << isPrimeNumber(7) << '\n';
20+
}

0 commit comments

Comments
 (0)