#include <stdio.h>
float function (float x, float y);
float function2 (float x, float z);
float function3 (float y, float z);
float main()
{
float x;
float y;
float z;
{
printf("Please insert length of adjacent side");
scanf("%f", &x);
printf("Please insert length of opposite side");
scanf("%f", &y);
printf("Please insert length of the hypotenuse");
scanf("%f", &z);
}
{
if (z = 0){
printf("The length of the hypotenuse is %f", function (x, y));}
else if (y = 0){
printf("The length of the opposite side is %f", function2(x, z));}
else if (x=0){
printf("The length of the adjacent side is %f", function3(y, z));}
}
}
float function(float x, float y) {
return(sqrt(((x*x)+(y*y))));
}
float function2(float x, float z) {
return(sqrt(((z*z)-(x*x))));
}
float function3(float y, float z){
return(sqrt(((z*z)-(y*y))));
}
这是我必须找出直角三角形缺失边的代码。您不知道的那一边的输入是 0。当我运行程序时,它会询问我所有的边,但它不会继续并给我答案……有人能解释一下吗? 谢谢
最佳答案
=
是赋值运算符。将 z = 0
和任何其他类似的替换为 z == 0
if (z == 0){ // = changed to ==
printf("The length of the hypotenuse is %f", function (x, y));}
else if (y == 0){ // = changed to ==
printf("The length of the opposite side is %f", function2(x, z));}
else if (x == 0){ // = changed to ==
printf("The length of the adjacent side is %f", function3(y, z));}
关于c - C 中的勾股定理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5162641/