#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.当我运行程序时,它询问我所有的方面,但它不会继续给我答案...有谁可以解释这个? 感谢
答案 0 :(得分:8)
=
是一个赋值运算符。使用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));}