相关讨论
今天写一个计算平方根的程序,
发现 没有 sqrt() 函数,我认为是我代码有问题,
于是写了几行简单的代码试一下,
代码如下:
[code]
#include ;
#include ;
int
main()
{
double ck;
ck=100.00;
ck=sqrt(ck);
printf("%f\n",ck);
return 1;
}
[/code]
但还是错误
提示如下:
/tmp/cc2DfpAZ.o(.text+0x2a): In function `main':
: undefined reference to `sqrt'
collect2: ld returned 1 exit sta...
請問下,Tuboc下的庫函數math.h在UNIX系統編譯下的名稱為何?
在两个不同的代码里面,一个找不到sqrt,而另外一个可以找到,不知道是为什么?
第一个代码是:
#include
#include
#include
struct Point {
int x;
int y;
};
typedef struct Point point;
double distance(point a, point b) {
int x,y;
x = abs(a.x - b.x);
y = abs(a.y...
我的系统是ubuntu-8.10-desktop-amd64,我想用函数sqrt(),但是编译出错.代码如下:
#include
#include
int main()
{
float fn, fres;
double dn, dres;
printf("Enter a float number: ");
scanf("%f", &fn);
fres = sqrtf(fn);
printf("The result of sqrt(%f) = %f\n", fn, fres);
printf("Enter a double number: ");
scanf("%lf", &dn);
dres = sqrt(dn);
print...
代码:/*try.c*/
#include
#include
main()
{
int a,b;
scanf("%d",&a);
b=sqrt(a);
printf("%d",b);
}
此代码在turboc下编译没有报错,但在unix下用cc -o try try.c 报错!难道在头文件math.h中没有sqrt()函数??
sqrt(25)-int(sqrt(25))在windows的计算器为什么不等于0
在lua(测试过了)是等于0的。
为什么啊:em14:
#include
#include
int
main()
{
float a, b, c, x1, x2, disc;
printf("input a,b,c : ");
scanf("%f,%f,%f\n", &a, &b, &c);
if (fabs(a) < 1e-6)
printf("the equation is not a quadratic");
else {
disc = b * b - 4 * a * c;
if (disc < 0)
printf("the equation has not rea...
#include
#include
int main(void)
{
float area=10;
area = sqrt(area);
return 0;
}
/*==========================
gcc test.c
/tmp/cc6oUCa1.o(.text+0x4b): In function `main':
test.c: undefined reference to `sqrt'
collect2: ld 返回 1
=====================*/
如果把 area = sqrt(area);改为 area = sqrt(10);
就没问题,为什么呢?
在SCO UNIX下/usr/include/math.h中有 math.h:extern double sqrt(double);
为什么我写程序时调用该函数调不了,报了一个找不到该函数ndefined first referenced
symbol in file
sqrt 3e.o
i386ld fatal: Symbol referencing errors. No output written to 3e
怎样能调用该函数?