Logical AND combines several conditions in such a way that the if part of if-else statement will execute only when all conditions are true.
Syntax-:
if(condition&&condition&&condition)
{
____________
____________
____________
____________
}
else
{
____________
____________
____________
____________
}
Logical OR in if statement combines several conditions in such a way that the if part will execute for any true condition.
the else statement executes only when all conditions are false.
Syntax-:
if(condition||condition||condition)
{
____________
____________
____________
____________
}
else
{
____________
____________
____________
____________
}
#include< stdio.h>
#include< conio.h>
void main()
{
char n,l;
int a;
clrscr();
printf("Enter your nationality if you are indian press i else press o");
scanf("%c",&n);
fflush(stdin);
printf("if you have driving license press y else press n");
scanf("%c",&l);
printf("Enter your age");
scanf("%d",&a);
if(n=='i'&&l=='y'&&a>18)
{
printf("elligible for job");
}
else
{
printf("not elligible for job");
}
getch();
}
Logical NOT-: when added to a condition in if else statement it works for exact opposite of that condition, while working with logical not in if else statement we must take care of our true and false blocks.
Syntax-:
if(NOT condition)
{
____________
____________
____________
____________
}
else
{
____________
____________
____________
____________ }