C++
- voluntas
- @ignis_fatuus
- ブン
- @Linda_pp
- 清楚なC++メイドBOT
- @tzik_tack
- 長谷川一輝
- wraith13
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- Siv3D
- @okdshin
- @hnokx
- @ishidakei
- @take_cheeze
- TAKEI Yuya
- @mumumu
- I (@wx257osn2)
- Tommy6
- わたやん
- @KorekaraSEDB
- @kariya_mitsuru
- @ciniml
- @beam2d
- @grafi_tt
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
37
1
2
using namespace std;3
4
int prime(int a);5
6
int main(){7
8
int number {};9
10
cout << "Enter a number that you want to check if it is prime or not : " ;11
cin >> number;12
13
prime(number);14
}15
16
int prime(int a){17
bool all_not_divisible = true;18
19
for (int i = 2; i < a ; i++)20
{21
if (a%i == 0)22
{23
all_not_divisible = false; // divisor found!24
}25
}26
27
if (a >= 2 && all_not_divisible)28
{29
cout << a << " is a prime number." << endl;30
}else31
{32
cout << a << " is not a prime number." << endl;33
}34
35
return 0;36
}37
$ g++ prog.cc -Wall -Wextra -std=c++11 -pedantic
Stdin
1Start
Enter a number that you want to check if it is prime or not : 1 is not a prime number.
0
Finish