Online Snippets Library

Compare three integers in C

To Compare 3 intergers in C, We need to compare value of one variable with rest of two varibles,Same process is applied for all variables.

C Program
#include <stdio.h>

int main() {
   int num1, num2, num3;

   num1 = 11;
   num2 = 25;
   num3 = 44;

   if ( num1 > num2 && num1 > num3 )
      printf("%d is the largest.", num1);
   else if ( num2 > num1 && num2 > num3 )
      printf("%d is the largest.", num2);
   else if ( num3 > num1 && num3 > num2 )
      printf("%d is the largest.", num3);
   else   
      printf("Values are not unique");

   return 0;
}

Output

44 is the largest.