View All C Programs

 Previews Example  View All C Programs Next Example 

Program to Find the Largest Number Among Three Numbers in C

In this program user is asked to enter three numbers and this program will find the largest number among three numbers entered by user.
#include <stdio.h>
#include <conio.h>
 main(){
      int a, b, c;
      printf("Enter three numbers: ");
      scanf("%d %d %d", &a, &b, &c);
      if(a>=b && a>=c)
      	{
         printf("Largest number = %d", a);
        }
      if(b>=a && b>=c)
        {
         printf("Largest number = %d", b);
        }
      if(c>=a && c>=b)
        {
         printf("Largest number = %d", c);
        }
      getch()
}
/* C program to find largest number using if...else statement */

#include <stdio.h>
int main(){
      int a, b, c;
      printf("Enter three numbers: ");
      scanf("%d %d %d", &a, &b, &c);
      if (a>=b)
      {
          if(a>=c)
            printf("Largest number = %d",a);
          else
            printf("Largest number = %d",c);
      }
      else
      {
          if(b>=c)
            printf("Largest number = %d",b);
          else
            printf("Largest number = %d",c);
      }
      return 0;
}
/* C program to find largest number using if...else statement */

/* C Program to find largest number using nested if...else statement */

#include <stdio.h>
int main(){
      int a, b, c;
      printf("Enter three numbers: ");
      scanf("%d %d %d", &a, &b, &c);
      if(a>=b && a>=c)
         printf("Largest number = %d", a);
      else if(b>=a && b>=c)
         printf("Largest number = %d", b);
      else
         printf("Largest number = %d", c);
      return 0;
}
Result
Enter three numbers: 15
10
5

Largest number = 15