Logical Operators:
They are....
- Logical AND - &&
- Logical OR - ||
- Logical NOT - !
We will see their examples for better understanding.
Program using logical AND:
#include<stdio.h>
void main()
{
int i;
for(i=0;i<10;i++)
{
if(i>0 && i>5)
{
printf("%d\n",i);
}
if(i>0 && i>5)
{
printf("%d\n",i);
}
}
}
In AND operator both conditions need to be true then only it will enter inside the if block, otherwise not.
OUTPUT:
Program using logical OR:
#include<stdio.h>
void main()
{
int i;
for(i=0;i<10;i++)
}
In AND operator both conditions need to be true then only it will enter inside the if block, otherwise not.
OUTPUT:
Program using logical OR:
#include<stdio.h>
void main()
{
int i;
for(i=0;i<10;i++)
{
if(i>0||i>5)
if(i>0||i>5)
{
printf("%d ",i);
printf("%d ",i);
}
}
}
In OR operator if any one or both conditions are true then this enters inside the if block otherwise not.
OUTPUT:
Program using logical NOT:
#include<stdio.h>
void main()
{
int i;
for(i=0;i<10;i++)
if(i!=5)
printf("%d ",i);
}
If we don't want to print any value of the loop then we can use the NOT operator.
OUTPUT
}
In OR operator if any one or both conditions are true then this enters inside the if block otherwise not.
OUTPUT:
Program using logical NOT:
#include<stdio.h>
void main()
{
int i;
for(i=0;i<10;i++)
if(i!=5)
printf("%d ",i);
}
If we don't want to print any value of the loop then we can use the NOT operator.
OUTPUT
No comments:
Post a Comment
If you have any doubts, please discuss here...👇