What are relational operators in C language?



These are used for comparing the two expressions.

OperatorDescriptionExamplea=10,b=20Output
<less thana<b10<201
<=less than (or) equal toa<=b10<=201
>greater thana>b10>200
>=greater than (or) equal toa>=b10>=200
==equal toa==b10==200
!=not equal toa!=b10!=201

Relational expression output is either true (1) (or) false (0).

Algorithm

Follow the algorithm given below −

START
Step 1: Declare integer variables.
Step 2: Read all variables at runtime.
Step 3: Perform relational operations.
   i. a<b
   ii. a<=b
   iii. a>b
   iv. a>=b
   v. a==b
   vi. a!=b
Step 4: Print all computed values.

Example

Following is the C program to compute relational operators −

 Live Demo

#include<stdio.h>
main (){
   int a,b;
   printf("enter a,b values:
");    scanf("%d%d",&a,&b);    printf("%d
",a<b);    printf("%d
",a<=b);    printf("%d
",a>b);    printf("%d
",b>=a);    printf("%d
",a==b);    printf("%d
",a!=b); }

Output

You will see the following output −

enter a,b values:
120 340
1
1
0
1
0
1

Advertisements