gpt4 book ai didi

c - 双重之前的预期表达

转载 作者:太空宇宙 更新时间:2023-11-04 05:38:55 24 4
gpt4 key购买 nike

一直说在double int pt函数之前有一个预期的表达式

 #include <stdio.h>
int pt (int a, int b)
{
int c, result;
c = (a * a) + (b + b);
result = double sqrt (double c);
return result;
}
int main (void)
{
int d, e, f;
int pt (int a, int b);
printf("type enter after input of the two legs");
scanf("%i", &d);
scanf("%i", &e);
f = pt (d,e);
printf("the hypotenuse is %i", f);
return 0;
}

最佳答案

改变

result = double sqrt (double c);

result = sqrt(c);

你不必投c进入 double当你把它传递给 sqrt由于隐式转换的功能。如果您仍然想进行转换,正确的方法是 sqrt((double) c) .

此外,#include <math.h>用于 sqrt功能。


注意:不需要转换 sqrt 的返回类型至 int (相关,因为 result 属于 int 类型)——但是一些编译器可能会发出有关隐式转换的警告(归功于@MattMcNabb)。将转换放入以向其他编码员发出精度损失是故意的信号也是一种很好的做法。

关于c - 双重之前的预期表达,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24770673/

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