Find Largest Number Among Three Numbers C Program

By | August 21, 2016

C Program To Find Largest Number Among Three Numbers

Learn How To Find Largest Number in Three Numbers in C Programming Language. Find the Maximum Integer among three different Integers by using Comparison Operators.

We have demonstrated the use of If – Else Block and Conditional Operators to Check which Number is greatest from the three given Numbers. The Conditional Operators are also known as Ternary Operators.

Must Read: C Program To Convert Fahrenheit Temperature into Celsius

C Program To Calculate Largest Number Among Three Integers using If – Else Block

#include<stdio.h>

int main()
{
      int num1, num2, num3;
      printf("\nEnter The Value of First Number:\t");
      scanf("%d", &num1);
      printf("\nEnter The Value of Second Number:\t");
      scanf("%d", &num2);
      printf("\nEnter The Value of Third Number:\t");
      scanf("%d", &num3);
      if((num1 > num2) && (num1 > num3))
      {
            printf("\nMaximum Number:\t%d\n", num1);
      }
      else if((num2 > num1) && (num2 > num3))
      {
            printf("\nMaximum Number:\t%d\n", num2);
      }
      else
      {
            printf("\nMaximum Number:\t%d\n", num3);
      }
      return 0;
}

Must Read: C Program To Convert Binary Value To Decimal Number

C Program To Find Largest Number of Three Numbers using Conditional Operators

#include<stdio.h>

int main()
{
      int num1, num2, num3, largest;
      printf("\nEnter The Value of First Number:\t");
      scanf("%d", &num1);
      printf("\nEnter The Value of Second Number:\t");
      scanf("%d", &num2);
      printf("\nEnter The Value of Third Number:\t");
      scanf("%d", &num3);
      largest = (((num1 > num2) && (num1 > num3)) ? num1 : (((num2 > num1) && (num2 > num3)) ? num2 : num3));	
      printf("\nMaximum Number:\t%d\n", largest);	
      return 0;
}

Must Read: C Program To Find Addition of Odd Numbers

 

C Program To Find Maximum Number from Three Numbers using Functions

#include<stdio.h>

int compare(int x, int y, int z)
{
      int largest = 0;
      if((x > y) && (x > z))
      {
            largest = x;
      }
      else if((y > x) && (y > z))
      {
            largest = y;
      }
      else
      {
            largest = z;
      }
      return largest;
}

int main()
{
      int num1, num2, num3, maximum;
      printf("\nEnter The Value of First Number:\t");
      scanf("%d", &num1);
      printf("\nEnter The Value of Second Number:\t");
      scanf("%d", &num2);
      printf("\nEnter The Value of Third Number:\t");
      scanf("%d", &num3);
      maximum = compare(num1, num2, num3);
      printf("\nMaximum Number:\t%d\n", maximum);	
      return 0;
}

Must Read: C Program To Calculate Addition of Two Numbers using Function

 

Output

C Program To Find Largest Number Among Three Numbers using If Else and Conditional Operators

In case you get any Compilation Errors or any doubts in this C Program To Find Greatest Number among Three Integers using If – Else Block or Conditional Operators, let us know about it in the Comment Section below.

Let's Discuss