1.基础,判断素数
#include <iostream>
#include <math.h>
using namespace std;
/*判断素数*/
int isprime(int number)
{
if(number<2){
return 0;
}else{
for(int i=2;i<=sqrt(number);i++){
if(number % i == 0){
return 0;
}
}
return 1;
}
}
int main()
{
int number = 0;
cin >> number;
if(isprime(number)){
cout << "the number is prime"<< endl;
}else{
cout << "the number is not prime" << endl;
}
return 0;
}
本文来自博客园,作者:TCcjx,转载请注明原文链接:https://www.cnblogs.com/tccjx/p/17652602.html