In C language can we write something like: if (10<=x<100) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 ?

25th Jul 2023, 8:31 PM
Dharmraj
3 Answers
+ 8
A typical way to code the relation 10<=x<100 is by using a logical AND: if (10<=x && x<100)
25th Jul 2023, 11:21 PM
Brian
Brian - avatar
+ 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
26th Jul 2023, 4:07 AM
Bob_Li
Bob_Li - avatar
+ 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
25th Jul 2023, 9:19 PM
HungryTradie
HungryTradie - avatar