'commit'
This commit is contained in:
23
C++专题课程/基础知识/判断素数.cpp
Normal file
23
C++专题课程/基础知识/判断素数.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int is_sushu(int n) {
|
||||
int i, mid;
|
||||
mid=(int)sqrt(n);
|
||||
for(i=2; i<=mid; i++)
|
||||
if(0 == n%i)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
int main() {
|
||||
int n;
|
||||
|
||||
printf("Enter a num: ");
|
||||
scanf("%d", &n);
|
||||
if(is_sushu(n))
|
||||
printf("%d is sushu!\n", n);
|
||||
else
|
||||
printf("%d is not sushu...\n", n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user