How to use If Statement Indirectly to solve expression ?
Indirect Use of If Statement : Expression Solving
How to Decide Expression Contain Invisible If Statement ?
How to solve Expression such as [ x = a > 5 ] ? What will be the output after printing the value of “x” ? This typical Question comes under “Invisible / Indirect use of If Statement “.
If Expression Contain Following Operators then given expression is of type - “Invisible / Indirect use of If Statement “.
- <
- >
- <=
- >=
- ==
- !=
#include<stdio.h> void main() { int num1 = 100,num2=200,num3; num3 = ( num1 >= 100 ) + (num2 < 50 ); printf("%d",num3); }
Output :
1
How ?
Writing
num3 = ( num1 >= 100 );
is as good as writing
if( num1 >= 100 ) num3 = 1; else num3 = 0;
Note : While Solving Such Expression always Check whether the expression Statement is True or False. If Expression is true then Replace 1 instead of that expression otherwise replace that expression with 0
num3 can be Calculated as -
num3 = ( num1 >= 100 ) + (num2 < 50 ); num3 = 1 + (num2 < 50 ); // ( num1 >= 100 ) is True num3 = 1 + 0; // (num2 < 50 ) is False num3 = 1;
Example 1 : c = !(a>=0) >= 0
Example 2 : c = !a<=!(c=b);