- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are relational operators in C language?
These are used for comparing the two expressions.
Operator | Description | Example | a=10,b=20 | Output |
---|---|---|---|---|
< | less than | a<b | 10<20 | 1 |
<= | less than (or) equal to | a<=b | 10<=20 | 1 |
> | greater than | a>b | 10>20 | 0 |
>= | greater than (or) equal to | a>=b | 10>=20 | 0 |
== | equal to | a==b | 10==20 | 0 |
!= | not equal to | a!=b | 10!=20 | 1 |
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 −
#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