C Program to Demonstrate Comparison Operator

C Program to Demonstrate Comparison Operator

List of C Programs
List of All Programs

C Code for comparison operator

//Write a C program to demonstrate comparison operator

#include <stdio.h>

int main()
{
    int a = 10, b = 8, c = 8;

    printf("The value of a : %d\n",a);
    printf("The value of b : %d\n",b);
    printf("The value of c : %d\n",c);

    //Comparison operator return 1 if true, else return 0
    printf("\n\na == b : %d \n",  a == b);
    printf("a == c : %d \n",  a == c);
    printf("a > b : %d \n",  a > b);
    printf("a > c : %d \n",  a > c);
    printf("a < b : %d \n",  a < b);
    printf("a < c : %d \n",  a < c);
    printf("a != c : %d \n", a != c);
    printf("a != b : %d \n",  a != b);
    printf("a >= b : %d \n",  a >= b);
    printf("a >= c : %d \n",  a >= c);
    printf("a <= b : %d \n",  a <= b);
    printf("a <= c : %d \n",  a <= c);

    return 0;
}

Output:

The value of a : 10
The value of b : 8
The value of c : 8

a == b : 0
a == c : 0
a > b : 1
a > c : 1
a < b : 0
a < c : 0
a != c : 1
a != b : 1
a >= b : 1
a >= c : 1
a <= b : 0
a <= c : 0