0
In C language can we write something like: if (10<=x<100)
If(10<=x<100) { printf("%d is a two digit number",x); } //Is this a correct method ?
3 Réponses
+ 8
A typical way to code the relation 10<=x<100 is by using a logical AND:
if (10<=x && x<100)
+ 2
HungryTradie
interesting use of ==
so
a==b
is equivalent to
!(a^b)
printf("\n!(a^b):\n");
printf("%d\n", !(1^1));
printf("%d\n", !(1^0));
printf("%d\n", !(0^1));
printf("%d\n", !(0^0));
printf("\na==b:\n");
printf("%d\n", 1==1);
printf("%d\n", 1==0);
printf("%d\n", 0==1);
printf("%d\n", 0==0);
external discussion about the difficulty of chaining booleans:
https://softwareengineering.stackexchange.com/questions/316969/why-do-most-mainstream-languages-not-support-x-y-z-syntax-for-3-way-boolea
+ 1
Interesting MO ELomari
Could we evaluate both sides, then evaluate true?
if ((x < 100)==(10 <= x))
{
printf("%d is between 10 and 100", x);
}
https://code.sololearn.com/cYtfyP2Binxo/?ref=app