#include<iostream>
using namespace std;
bool isSushu(int);//檢查是否是素數(shù)
void main()
{
int a;
cout<<"請輸入數(shù)字:";
cin>>a;
if (isSushu(a))
{
cout<<a<<"是一個素數(shù)"<<endl;
}
else
{
cout<<a<<"不是一個素數(shù)"<<endl;
}
}
bool isSushu(int a)
{
if (a==2)
{
return true;
}
for(int i=2;i<a;i++)
{
if (a%i==0)
{
return false;
}
}
return true;
}
【數(shù)學(xué)之美】很高興為你解答,不懂請追問!滿意請采納,謝謝!O(∩_∩)O~