RELATIONAL OPERATOR IN C

Relational Operator in C

Operators

An operator is a symbol, which helps the user to command the computer to do certain mathematical or logical manipulations. C includes a large number of operators which fall into different categories. In this lesson, we will see how arithmetic operators, unary operators, relational and logical operators, assignment operators, and conditional operators are used to form expressions.

Relational Operator in C

The relational operator is some kind of relation between two operands. It checks numerical equally or non equally conditions. This operator is very useful in conditional programs when we check conditions between two operands.

Relational Operator in C

 

 

1. Less than(<):

Indicates whether the value of the left operand is less than the value of the right operand.

2. Greater than(>)

Indicates whether the value of the left operand is greater than the value of the right operand.

3. Less than or equal to(<=)

Indicates whether the value of the left operand is less than or equal to the value of the right operand.

4. Greater than or equal to(>=)

Indicates whether the value of the left operand is greater than or equal to the value of the right operand.

5. Equal to(==)

Indicates whether the value of the left operand is equal to the value of the right operand.

6. Not equal to(!=)

Indicates whether the value of the left operand is not equal to the value of the right operand.

 

Program

include <stdio.h> 
int main() 
{ 
int a = 20; 
int b = 10; 
int c ; 
if( a == b )
 { 
printf("a is equal to b\n" );
 }
 else
 {
 printf("a is not equal to b\n" );
 } 
if ( a < b )
 { 
printf("a is less than b\n" );
 } 
else
 { printf("a is not less than b\n" );
 } 
if ( a > b )
 { 
printf("a is greater than b\n" );
 } 
else
 { 
printf("a is not greater than b\n" );
 }'
 if ( a <= b ) 
{ 
printf("a is either less than or equal to b\n" );
 } 
else
{
printf("a is not less than or equal to b\n" );
}
if ( b >= a ) 
{
 printf("b is either greater than or equal to a\n" );
 }
else
{
printf("b is not greater than or equal to a\n" );
} 
}

 

Output

a is not equal to b 
a is not less than b
a is greater than b 
a is not less than or equal to b
b is either greater than or equal to a

 

Also read the Control Statement in C

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *