- C Programming Examples
- C Programming Examples
- C Print Hello World
- C Take Input from User
- C Print Integer
- C Add two Numbers
- C Check Even or Odd
- C Check Prime or Not
- C Check Alphabet or Not
- C Check Vowel or Not
- C Check Leap Year or Not
- C Check Reverse equal Original
- C Add Subtract Multiply & Divide
- C Make Calculator
- C Add Digits of Number
- C Calculate Average & Percentage
- C Calculate Arithmetic Mean
- C Calculate Student Grade
- C Print Table of Number
- C Print Prime Numbers
- C Add n Numbers
- C Interchange Numbers
- C Reverse Numbers
- C Swap two Numbers
- C Count Positive Negative & Zero
- C Find Largest of two Numbers
- C Find Largest of three Numbers
- C Find Factorial of Number
- C Find HCF & LCM
- C Calculate Area & Perimeter
- C Calculate Area & Circumference
- C Convert Fahrenheit to Centigrade
- C Convert Centigrade to Fahrenheit
- C Print ASCII Values
- C Print Fibonacci Series
- C Check Palindrome or Not
- C Check Armstrong or Not
- C Generate Armstrong Numbers
- C Find ncR nPr
- C Convert Decimal to Binary
- C Convert Decimal to Octal
- C Convert Decimal to Hexadecimal
- C Convert Binary to Decimal
- C Convert Binary to Octal
- C Convert Binary to Hexadecimal
- C Convert Octal to Decimal
- C Convert Octal to Binary
- C Convert Octal to Hexadecimal
- C Convert Hexadecimal to Decimal
- C Convert Hexadecimal to Binary
- C Convert Hexadecimal to Octal
- C Pattern Printing Programs
- C Print Diamond Pattern
- C Print Floyd Triangle
- C Print Pascal Triangle
- C Print smiling face
- C One Dimensional Array Program
- C Linear Search
- C Binary Search
- C Add Two Numbers using Pointer
- C Find Largest Element in Array
- C Find Smallest Element in Array
- C Reverse Array
- C Insert Element in Array
- C Delete Element from Array
- C Merge two Array
- C Bubble Sort
- C Selection Sort
- C Insertion Sort
- C Two Dimensional Array Program
- C Add two Matrices
- C Subtract Matrices
- C Transpose Matrix
- C Multiply Matrices
- C Three Dimension Array Program
- C Print String
- C Find Length of String
- C Compare two String
- C Copy String
- C Concatenate String
- C Reverse String
- C Delete Vowels from String
- C Delete Words from Sentence
- C Find Frequency of Character
- C Count Word in Sentence
- C Remove Spaces from String
- C Sort a String
- C Convert Uppercase to Lowercase
- C Convert Lowercase to Uppercase
- C Swap two Strings
- C Check Anagram or Not
- C Generate Random Numbers
- C Read File
- C Write to File
- C Read & Display File
- C Copy File
- C Merge two File
- C List Files in Directory
- C Delete File
- C Encrypt and Decrypt Files
- C Print Date
- C Get IP Address
- C Shutdown Computer
- C New Programs
- C Check String Palindrome
- C Count in file
- C Count with/without Space
- C Smallest of Three Numbers
- C Smallest of Two Numbers
- C Sum of Matrix Elements
- C Programming Tutorial
- C Tutorial
- C Programming Library
- C Standard Library
- C Programming Test
- C Programming Test
- Give Online Test
- Register Now
- Login
- All Test List

In this tutorial, we will learn about how to find and print largest of any given three numbers (by user at run-time) with and without using function and also using ternary operator.

To find the largest number among given three numbers in C programming, you have to ask from the user to enter any three number, now
start checking which one is the largest number using **if-else** block. After finding the largest one among given three, display that
number as the largest number of the three number.

Following C program ask from the user to enter any three numbers to check which one is the largest or biggest, then display the result on the screen:

// Write a program in C to find and print greatest // or largest of any given three numbers by user // ---------codescracker.com---------- #include<stdio.h> #include<conio.h> int main() { int a, b, c, big; printf("Enter three numbers: "); scanf("%d%d%d", &a, &b, &c); if(a>b) { if(b>c) big = a; else { if(c>a) big = c; else big = a; } } else { if(b>c) big = b; else big = c; } printf("\nLargest number = %d", big); getch(); return 0; }

As the above program was written under **Code::Blocks** IDE, therefore after successful build and run, you will get the following
output as shown here in the snapshot given below:

Supply any three numbers say **3**, **1**, and **2** and press ENTER key to see the largest number as given in the
second snapshot of the sample run:

Let's take another sample run for the same above program. Here is the final snapshot of the second sample run:

Here is the final snapshot of the third sample run:

In all cases that when you will supply:

- first number as largest & second number as second largest
- first number as largest & third number as second largest
- second number as largest & first number as second largest
- second number as largest & third number as second largest
- third number as largest & first number as second largest
- third number as largest & second number as second largest

You will only get the greatest number as output.

Here are some of the main steps used in above program:

- Receive three numbers as input and store it inside the three variables as first, second and third number say
**a**,**b**and**c** - Check whether the first number say
**a**is greater than the second number say**b** - If it is, then go to the
**if**block and check whether the value inside**b**is also greater than**c** - If it is, then the value present at the first number say
**a**will be initialized to the variable**big**, otherwise, check whether the third number say**c**is greater than the first number say**a** - If it is, then the vaulue present at
**c**gets initialized to**big**, otherwise intialize**a**to**big**and come out from the**if**block - And if
**a**is less than**b**, then check whether**b**is greater than**c** - If it is, initialize the value of
**b**to**big**, otherwise initialize the value of**c**to**big** - Print the value of
**big**variable as output, that will be the largest value among the given three numbers

You can also use the following program to find out the largest among the given three numbers:

// Write a program in C to find out the // largest of any given three numbers // ---------codescracker.com---------- #include<stdio.h> #include<conio.h> int main() { int a, b, c, big; printf("Enter three numbers: "); scanf("%d%d%d", &a, &b, &c); if(a>b && a>c) big = a; else if(b>a && b>c) big = b; else big = c; printf("\nLargest number = %d", big); getch(); return 0; }

The above program is little bit simple to create and understand in comparison to the above one. This will also calculates and print the largest number among any given three numbers.

Here I'm going to create the same program, that is to find out and print the largest among given three numbers, but this time using the ternary operator. Let's take a look at the program:

// Write a program in C, which take three integer // values and print largest or maximum Value // using Ternary Operator // -----------codescracker.com----------- #include<stdio.h> #include<conio.h> int main() { int num1, num2, num3, large; printf("Enter any three numbers: "); scanf("%d%d%d", &num1, &num2, &num3); large = (num1>num2) ? ((num1>num3)?num1:num3) : ((num2>num3)?num2:num3); printf("Largest/Maximum number = %d", large); getch(); return 0; }

After successfully build and run the above program, here is the first screenshot of the sample run:

Now supply any three numbers as input say **12**, **23**, and 11 and then press `ENTER`

to see the output.
Here is the second snapshot of the sample run:

Here are some of the main steps used in above program:

- Receive any three numbers as input say
**num1**,**num2**, and**num3** - Use ternary operator (?:) and initialize the largest to the variable say
**large** - Here if value at
**num1**greater than value at**num2**- and value at
**num1**is also greater than value at**num3**- then
**num1**will be initialized to**large** - otherwise
**num3**will be initialized to**large**

- then

- and value at
- And if
**num2**is greater than**num1**- and
**num2**is also greater than**num3**- then
**num2**will be initialized to**large** - otherwise
**num3**will be initialized to**large**

- then

- and
- Print the value of variable
**large**that holds the largest value

Here we have used nested ternary operator, that is ternary operator inside the ternary operator.

Now let's find out the largest among any given three numbers using any user-defined function. Here we have created a function
named **findLarge()** that will take three values as argument and will return the largest among these three numbers. Here is the
program:

// Write a program in C to find out the // largest of any given three numbers // using user-defined function // ---------codescracker.com---------- #include<stdio.h> #include<conio.h> int findLarge(int, int, int); int main() { int a, b, c, big; printf("Enter three numbers: "); scanf("%d%d%d", &a, &b, &c); big = findLarge(a, b, c); printf("\nLargest number = %d", big); getch(); return 0; } int findLarge(int num1, int num2, int num3) { if(num1>num2) { if(num2>num3) return num1; else { if(num3>num1) return num3; else return num1; } } else { if(num2>num3) return num2; else return num3; } }

Here is the final snapshot of the sample run:

Here the function takes the three given numbers as its argument and will return the largest one that will be initialized to the
variable say **big**. Print the value of big that will hold the largest value among the given three numbers.

You may also like same program in other programming languages:

- C++ Find Largest of three Numbers
- Java Find Largest of three Numbers
- Python Find Largest of three Numbers