素数和sqrt函数

来源:互联网 发布:地震能被预测吗 知乎 编辑:程序博客网 时间:2024/06/05 22:54

http://c.biancheng.net/cpp/html/2547.html  素数

在vs2013c++编译器中运行:

#include<stdio.h>
#include<math.h>
int main()
{
int a = 5;
//printf("%d\n", (int)sqrt(a));//error 1
printf("%d\n", (int)sqrt((double)a));
return 0;


}
//--------error 1错误的原因----------//
//IntelliSense:  有多个 重载函数 "sqrt" 实例与参数列表匹配 :
//函数 "sqrt(double _X)"
//函数 "sqrt(float _X)"
//函数 "sqrt(long double _X)"
//参数类型为 : (int)c 
//错误 1 error C2668: “sqrt”: 对重载函数的调用不明确

所以对于该编译器:int a必须前面加(double)强制转换为double型

0 0
原创粉丝点击