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:\n"); scanf("%d%d",&a,&b); printf("%d\n",a<b); printf("%d\n",a<=b); printf("%d\n",a>b); printf("%d\n",b>=a); printf("%d\n",a==b); printf("%d\n",a!=b); }
Output
You will see the following output −
enter a,b values: 120 340 1 1 0 1 0 1