[英]C program taking in three integers and seeing if they make a triangle and a right angle
I was given a question from an assignment that asks me to make a program where the user enters 3 integers and then it checks to see if they can be sides of a triangle.我从一项作业中得到了一个问题,要求我制作一个程序,用户输入 3 个整数,然后检查它们是否可以是三角形的边。 I am supposed to use a nested
if
statement for this, I cannot use &&
in the statements and the formula they gave me is我应该为此使用嵌套的
if
语句,我不能在语句中使用&&
并且他们给我的公式是
num1 < num2 + num3 AND num1 < num2 - num3
I am very confused on this and any help would be appreciated!我对此感到非常困惑,任何帮助将不胜感激!
The question appears to be asking how to implement a logical AND using nested if
statements rather than &&
operators.问题似乎是在询问如何使用嵌套的
if
语句而不是&&
运算符来实现逻辑 AND。
if (X && Y) foo;
is equivalent to if (X) if (Y) foo;
等价于
if (X) if (Y) foo;
. .
int a=1, b=2, c=3;
if (a<b+c)
{
if (a<b-c)
printf("Yes");
}
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("TRUE\n");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.