永发信息网

用VS 2013 输出出50-100之间的素数

答案:1  悬赏:60  手机版
解决时间 2021-03-27 16:36
  • 提问者网友:我是女神我骄傲
  • 2021-03-27 07:27
用VS 2013 输出出50-100之间的素数
最佳答案
  • 五星知识达人网友:街头电车
  • 2021-03-27 07:58
#include 
#include 
int ss(int m)

int i,t1=0,q; 
q=sqrt(m); 
for (i=2;i<=q;i++)  if (m%i==0) break;  
if (i>=q+1) t1=1; 
return(t1); 

int main() 
{
int i,t=0; 
for (i=50;i<=100;i++) {
t=ss(i);
if (t==1)  printf("%4d",i);

return 0;
}追问那个sqrt不行 说有多个重载函数追答重载函数? 是你有函数声明 还是vs中库的问题啊。。我在vc6.0中能正常编译通过。。追问我也不知道啊,它说对重载函数调用不明确.追答sqrt不行是什么意思? 没有用到这个函数啊,应该是你用了这个函数,注意看下函数的参数要配套!追问错误 2 error C3861: “sqrt”: 找不到标识符 c:\users\len\documents\visual studio 2013\projects\consoleapplication5\consoleapplication5\consoleapplication5.cpp 7 1 ConsoleApplication5 我就是按照你的弄得!!5555555追答我刚看到。哈哈。。刚才查了下
VS 2008以后 sqrt为重载函数,原型为 float sqrt (float),double sqrt (double),double long sqrt(double long)
注意没有sqrt (int),但是返回值可以为int ,咱那个参数是 int 类型的,你可以把它强制转换成 double类型 或者 是把
int ss(double m) //把这个参数改成double类型。。
{
int i,t1=0,q;
q=sqrt(m);
for (i=2;i<=q;i++) if (m%i==0) break;
if (i>=q+1) t1=1;
return(t1);
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯