gpt4 book ai didi

c - 这个错误是什么意思?

转载 作者:太空狗 更新时间:2023-10-29 15:53:16 26 4
gpt4 key购买 nike

/tmp/ccjiJKv2.o: In function func':<br/>
b.c:(.text+0x16b): undefined reference to
sqrt'
collect2: ld returned 1 exit status

这是代码,我使用的是 gcc 编译器..

/*Write a function that receive 5 integers and returns the sum,average and standard deviation of these numbers*/

/*Author:Udit Gupta Date:10/08/2011*/

#include<stdio.h>
#include<math.h>

void func (int *,float *,float *);

int main () {

float avg,std_dev;

int sum;

func (&sum,&avg,&std_dev); /*Passing address of variables where output will be stored.....*/

printf ("The sum of numbers is %d\n",sum);
printf ("The average of numbers is %f\n",avg);
printf ("The standard deviation of numbers is %f\n",std_dev);

}


void func (int *sum_, float *avg_ , float * std_dev_) {

int n1,n2,n3,n4,n5;

printf("Please enter the number:");
scanf("%d%d%d%d%d",&n1,&n2,&n3,&n4,&n5);


/*Formula for sum,average and standard deviation*/

*sum_ = n1+n2+n3+n4+n5; /*Writing output at the address specified by arguments of function*/
*avg_ = *sum_ / 5 ;
*std_dev_ = sqrt ( pow((n1-*avg_),2)+pow((n2-*avg_),2)+pow ((n3-*avg_),2)+pow ((n4-*avg_),2)+pow ((n5-*avg_),2)/4) ;

}

最佳答案

您没有链接包含 sqrt 的实现的库。

该库称为“libm”(数学库),可以按如下方式链接到:

gcc -o myprog infile.c -lm

关于c - 这个错误是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7043805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com