64,648
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <cmath>
using namespace std;
void main()
{
int m,i,k;
cout<<"请输入一个整数:"<<endl;
cin>>m;
k=sqrt(m);
for(i=2;i<=k;i++)
{
if(m%i==0)
break;
}
if(i>=k+1)
cout<<m<<" 是素数"<<endl;
else
cout<<m<<" 不是素数"<<endl;
}
1
2
3
4
5
6
7
8
9
10
11
12
/* sqrt example */
#include <stdio.h>
#include <math.h>
int main ()
{
double param, result;
param = 1024.0;
result = sqrt (param);
printf ("sqrt(%lf) = %lf\n", param, result );
return 0;
}
Output:
sqrt(1024.000000) = 32.000000
#include<iostream>
#include<cmath>
using namespace std;
for(i=2;i<=k;i++)