Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

Relational Operators in C

Relational Operator in C

The main use of this operator comparison two expression. The output of relational expression is either true(1) or false(0).

So what are operator that use for relational expression, (<,<=,>,>=,==,!=). These operator is called as a relational operator.

For example: checking if one operand is equal to the other operand or not, an operand is greater than the other operand or not etc.

 

Relational operator in C

Implementation of Relational operator

We know that Relational operator have six operator So, we can use this  operator in the below program.

Firstly we are use greater than the value of operator if the value is greater than print the greatest value.

second we are greater than or equal to value if the value is greater than or equal to the value than print the value.

third is the value is smaller then we can use the smallest value of two number and print the smallest value.

fourth is we are greater than or equal to value if the value is greater than or equal to the value than print the value.

fifth is  if the two value is same or equal then print the equal to value.

six is not equal to the value then print the value it is not equal of two number.

 

 

Code for Relational Operator

#include<stdio.h>




int main()

{

    int x = 10, y = 15;




    printf("x = %d\n", x);

    printf("y = %d\n\n", y);




    // Is x is greater than y?

    printf("x > y : %d\n", x > y);




    // Is x is greater than or equal to y?

    printf("x >= y : %d\n", x >= y);




    // Is x is smaller than y?

    printf("x < y : %d\n", x < y);




    // Is x is smaller than or equal to y?

    printf("x <= y : %d\n", x <= y);




    // Is x is equal to y?

    printf("x == y : %d\n", x == y);




    // Is x is not equal to y?

    printf("x != y : %d\n", x != y);




    // Signal to operating system everything works fine

    return 0;

}