一直说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;
}
Run Code Online (Sandbox Code Playgroud)
改变
result = double sqrt (double c);
Run Code Online (Sandbox Code Playgroud)
到
result = sqrt(c);
Run Code Online (Sandbox Code Playgroud)
由于隐式转换,当您将其传递给函数时,您不必强制c转换为 a 。如果你还想做演员表,正确的方法是.doublesqrtsqrt((double) c)
此外,#include <math.h>对于该sqrt功能的使用。
注:它不是必需投的返回类型sqrt,以int(相关,因为result是类型int) -但是有些编译器可以给出关于隐式转换的警告(感谢@MattMcNabb)。将演员表放入向其他编码员发出信号,表明精度损失是有意的,这也是一种很好的做法。