没有逻辑运算符如何制作这样的程序? (和&和)

时间:2015-10-04 03:51:19

标签: c++

#include <stdio.h>
int main()
{
    int x,y,z;

    printf ("Side x: ");
    scanf ("%d",&x);

    printf ("Side y: ");
    scanf ("%d",&y);

    printf ("Side z: ");
    scanf ("%d",&z);

    if (x+y>z&&x+z>y&&z+y>x)
        printf ("\nTriangle can be performed");
    else
        printf ("\nTriangle cannot be performed");
    return 0;
}

1 个答案:

答案 0 :(得分:0)

您可以使用嵌套的if语句。

triangle = false;
if (x + y > z) {
    if (x + z > y) {
        if (z + y > x) {
            triangle = true;
        }
    }
}
if (triangle) {
    printf("\nTriangle can be performed");
} else {
    printf("\n Triangle cannot be performed");
}