標(biāo)題:
C++語言判斷素數(shù)程序
[打印本頁]
作者:
daming
時間:
2014-12-30 02:03
標(biāo)題:
C++語言判斷素數(shù)程序
本帖最后由 daming 于 2014-12-30 02:16 編輯
#include<iostream.h>
#include<math.h>
int fc(int n)
{
int flag=0;
int i;
for(i=2;i<=sqrt(n);i++)
if(n%i==0)
flag=1;
return flag;
}
void main()
{
int n;
cout<<"input data:\n";
cin>>n;
if(fc(n)==0)
cout<<n<<"是素數(shù)\n";
else
cout<<n<<"是合數(shù)\n";
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1