求助:C语言中sqrt的调用?
来源:百度知道 编辑:UC知道 时间:2024/06/04 00:53:15
#include<stdio.h>
#include<math.h>
void main()
{long int t,a,b,x,y;
printf("6位分段和平方数有:");
t=(double)sqrt(100000);
for(b=t+1;b<=999;b++)
{a=b*b;
x=a/1000;y=a%1000;
if(b==(x+y))
printf("%ld ",a);
}
}
执行后出现error C2668: “sqrt”: 对重载函数的调用不明确
1> d:\软件\vc\vc\include\math.h(581): 可能是“long double sqrt(long double)”
1> d:\软件\vc\vc\include\math.h(533): 或 “float sqrt(float)”
1> d:\软件\vc\vc\include\math.h(128): 或 “double sqrt(double)”
1> 试图匹配参数列表“(int)”.
我用的是VC2008希望高手指点一下最好详细些~。~!!!
t=(double)sqrt(100000);源程序中是t=sqrt(100000)我更改后还是一样的反应
#include<math.h>
void main()
{long int t,a,b,x,y;
printf("6位分段和平方数有:");
t=(double)sqrt(100000);
for(b=t+1;b<=999;b++)
{a=b*b;
x=a/1000;y=a%1000;
if(b==(x+y))
printf("%ld ",a);
}
}
执行后出现error C2668: “sqrt”: 对重载函数的调用不明确
1> d:\软件\vc\vc\include\math.h(581): 可能是“long double sqrt(long double)”
1> d:\软件\vc\vc\include\math.h(533): 或 “float sqrt(float)”
1> d:\软件\vc\vc\include\math.h(128): 或 “double sqrt(double)”
1> 试图匹配参数列表“(int)”.
我用的是VC2008希望高手指点一下最好详细些~。~!!!
t=(double)sqrt(100000);源程序中是t=sqrt(100000)我更改后还是一样的反应
sqrt参数应该是float类型,将你的改为
t=(double)sqrt(100000.0);
原型:extern float sqrt(float x);
用法:#include <math.h>
功能:计算x的平方根。
说明:x应大于等于零。
举例:
// sqrt.c
#include <syslib.h>
#include <math.h>
main()
{
clrscr(); // clear screen
textmode(0x00); // 6 lines per LCD screen
printf("sqrt(2000)=%f",sqrt(2000.0));
getchar();
return 0;
}
相关函数:无
#include<stdio.h>
#include<math.h>
int main()
{
long t,a,b,x,y;
printf("6位分段和平方数有:");
t=(long)sqrt(100000);
for(b=t+1;b<=999;b++)
{
a=b*b;
x=a/1000;y=a%1000;
if(b==(x+y))
printf("%ld ",a);
}
}