我接到一个作业的问题,要求我制作一个程序,用户输入 3 个整数,然后检查它们是否可以是三角形的边。我应该为此使用嵌套的if
语句,我不能在语句中使用&&
,他们给我的公式是
num1 < num2 + num3 AND num1 < num2 - num3
我对此感到非常困惑,任何帮助将不胜感激!
问题似乎是在问如何使用嵌套的if
AND 语句而不是&&
运算符来实现逻辑 AND。
if (X && Y) foo;
相当于if (X) if (Y) foo;
。
if (num1 < num2 + num3) /* if this is true you enter the first scope */
{
if (num1 < num2 - num3) /* if this is also true enter the second scope */
{
printf("TRUEn");
}
}
int a=1, b=2, c=3;
if (a<b+c)
{
if (a<b-c)
printf("Yes");
}