Operators
Operator | Use |
== | Check value of 2 variable are equal |
!= | Check value of 2 variable are equal or not |
> | check is value is greater than |
>= | check is value is greater than or equal to |
< | check value is less than |
<= | check value is less than or equal to |
Example :
#include <stdio.h>
int main()
{
int a = 21;
int b = 10;
int c ;
// == operator
if( a == b )
{
printf("a is equal to b\n" );
}
else
{
printf("a is not equal to b\n" );
}
// < operator
if ( a < b )
{
printf("a is less than b\n" );
}
else
{
printf("a is not less than b\n" );
}
// > operator
if ( a > b )
{
printf("a is greater than b\n" );
}
else
{
printf("a is not greater than b\n" );
}
// Lets change value of a and b
a = 5;
b = 20;
// <= operator
if ( a <= b )
{
printf("a is either less than or equal to b\n" );
}
// >= operator
if ( b >= a )
{
printf("b is either greater than or equal to b\n" );
}
return 0;
}
Output :
a is not equal to b a is not less than b a is greater than b a is either less than or equal to b b is either greater than or equal to b
No comments:
Post a Comment