gpt4 book ai didi

c - C 中的勾股定理程序

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

#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 Operators Reference Sheet

关于c - C 中的勾股定理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5162641/

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