Home / Programs / Example program of Comparison Operators
Programming Example

Example program of Comparison Operators

👁 1,180 Views
💻 Practical Program
📘 Step by Step Learning

You may determine equality or difference among variables or values. Here is the list of comparison operatos:

== is equal to
!= is not equal
> is greater than
< is less than
>= is greater than or equal to
<= is less than or equal to

Program Code

#include <stdio.h>
int main() {
	int a,b;
	a = 10;
	b = 6;
	printf("%d == %d = %d\n",a,b,a==b);
	printf("%d != %d = %d\n",a,b,a!=b);
	printf("%d > %d = %d\n",a,b,a>b);
	printf("%d < %d = %d\n",a,b,a<b);
	printf("%d >= %d = %d\n",a,b,a>=b);
	printf("%d <= %d = %d\n",a,b,a<=b);
	return 0;
}

Output

10 == 6 = 0
10 != 6 = 1
10 > 6 = 1
10 < 6 = 0
10 >= 6 = 1
10 <= 6 = 0
Press any key to continue . . .

Explanation

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.