Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf52578c

Browse files
authored
Create 1.cpp
1 parent06a1d38 commitf52578c

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+
usingnamespacestd;
4+
5+
// 소수 판별 함수(2이상의 자연수에 대하여)
6+
boolisPrimeNumber(int x) {
7+
// 2부터 x의 제곱근까지의 모든 수를 확인하며
8+
for (int i =2; i <= (int)sqrt(x); i++) {
9+
// x가 해당 수로 나누어떨어진다면
10+
if (x % i ==0) {
11+
returnfalse;// 소수가 아님
12+
}
13+
}
14+
returntrue;// 소수임
15+
}
16+
17+
intmain() {
18+
cout <<isPrimeNumber(4) <<'\n';
19+
cout <<isPrimeNumber(7) <<'\n';
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp