Logical Operators:
- These operators return true (1) or false (0) by evaluating more than one expression.
- Operators are,
- Logical-AND (&&)
- Logical-OR (||)
- Logical-NOT (!)
- Following truth table represents the results of Logical operators’ evaluation
A | B | A&&B | A||B | !A | !B |
T | T | T | T | F | F |
T | F | F | T | F | T |
F | T | F | T | T | F |
F | F | F | F | T | T |
#include <stdio.h>
int main()
{
printf("5>3 && 5!=3 = %d \n", 5>3 && 5!=3);
printf("5>3 && 5==3 = %d \n", 5>3 && 5==3);
printf("5>3 || 5==3 = %d \n", 5>3 || 5==3);
printf("5<3 || 5==3 = %d \n", 5<3 || 5==3);
return 0;
}
Condition to check the number divisible by 3 and 5
N%3==0 && N%5==0
Condition to check First Num is greater than both Second & Third Nums
A>B && A>C
Condition to check the number divisible by 3 but not with 5
N%3==0 && N%5!=0
Condition to check the number is in between 30 and 50
N>=30 && N<=50
Condition to check the number is 3 digits number
N>=100 && N<=999
Condition to check the student passed in all 5 subjects
M1>=35 && M2>=35 && M3>=35 && M4>=35 && M5>=35
Condition to check the character is Vowel
CH==’A’ || CH==’E’ || CH==’I’ || CH==’O’ || CH==’U’
Condition to check the character is Upper case alphabet
CH>=’A’ && CH<=’Z’
Condition to check the character is digit
CH>=’0’ && CH<=’9’
Condition to check the character is Alphabet
(CH>=’A’ && CH<=’Z’) || (CH>=’a’ && CH<=’z’)
Condition to check the character is Symbol
!((CH>=’A’ && CH<=’Z’) || (CH>=’a’ && CH<=’z’)||( CH>=’0’ && CH<=’9’))
Condition to check the 3 numbers equal
A==B && B==C && C==A
Condition to check any 2 numbers equal or not among the 3 numbers
A==B || B==C || C==A
Condition to check the 3 numbers are unique
A!=B && B!=C && C!=A