C中的毕达哥拉斯定理程序

Mar*_*cus 0 c geometry

#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))));

}
Run Code Online (Sandbox Code Playgroud)

这是我必须弄清楚直角三角形缺失面的代码.你不知道的那边的输入是0.当我运行程序时,它询问我所有的方面,但它不会继续给我答案...有谁可以解释这个?谢谢

Tim*_*per 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));} 
Run Code Online (Sandbox Code Playgroud)

C运营商参考表

  • +1,'main`也应该是`int`.不是'漂浮'. (3认同)