C - Comparing values with comparison operator

Introduction

The following table lists C mathematical comparison operators.

Operator
Example
True When
!=
a != b
a is not equal to b
<
a < b
a is less than b
<=
a <= b
a is less than or equal to b
==
a == b
a is equal to b
>
a > b
a is greater than b
>=
a >= b
a is greater than or equal to b

Comparisons in C work from left to right.

Demo

#include <stdio.h> 

int main() //  w ww .j a  v a  2s  .  co m
{ 
   int first,second; 

   printf("Input the first value: "); 
   scanf("%d",&first); 
   printf("Input the second value: "); 
   scanf("%d",&second); 

   puts("Evaluating..."); 
   if(first<second) 
   { 
       printf("%d is less than %d\n",first,second); 
   } 
   if(first>second) 
   { 
       printf("%d is greater than %d\n",first,second); 
   } 
   return(0); 
}

Result

Related Topic