Online Snippets Library

Compare two integers in C

To Compare 2 intergers in C, We need to use if-else and greater than or less than operator. Complete program is given below.

C Program
#include <stdio.h>
int main() {
   int num1, num2;

   num1 = 22;
   num2 = 100;

   // to take values from user input uncomment the below lines −
   // printf("Enter value for A :");
   // scanf("%d", &a);
   // printf("Enter value for B :");
   // scanf("%d", &b);

   if(num1 > num2)
      printf("num1 is greater than num2");
      printf("num2 is  greater than num1");

   return 0;


num2 is greater than num1