天天看點

判斷是不是素數

#include <iostream>
using namespace std;
bool ff(int n) {
	int i;
	for(i=2;i<n;i++)
	{	
	  if(n%i==0)
	  break;
	}
	if(i==n)
	 return true;
	 else 
	 return false;
}
int main(){
	int d; 
	cin>>d;
	if(ff(d))
	cout<<" 是素數 ";
	else
	cout<<" 不是素數 " ; 
	return 0;
}
           

繼續閱讀