c - C 中的勾股定理程序

标签 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))));

}

这是我必须找出直角三角形缺失边的代码。您不知道的那一边的输入是 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/

相关文章:

C 语言 - 无法将 SIGINT 重置为默认值

c - 带有自定义 Makefile 的 Eclipse C 调试器

c++ - 线段球体相交测试c++

class - 检查一个圆是否包含在另一个圆中

c++ - 如何在 C++ 中将一般形式的二维直线方程转换为斜截式

python - 质心 Voronoi 镶嵌

javascript - 在集合矩形中拟合随机多边形的算法

c - 如何从 C 中的命令行参数读取 "string"?

c - #define 多行字符串

c - 使用数组将数字解码为字母