C Program to Find the Largest of three Numbers2 min read

In this tutorial, we will write a basic C Program to find the greatest of three numbers. You may go through the following topics in order to understand the C program.

Algorithm to find the largest among three numbers

  1.  Start.
  2. Read num1, num2 and num3 from user.
  3. Check num > num2, if true go to step 4 else go to step 5
  4. Check num1 > num3.
    • If true, print ‘num1 is the greatest number’.
    • If false, then print ‘num3 as the greatest number’.
    • go to step 6
  5. check if num2 > num3.
    1. If true, print ‘num2 as the greatest number’.
    2. If false, print ‘num3 as the greatest number’.
  6. Stop

C Program to find the Largest among three Numbers

We will find the greatest of three using if..else and if…else-if statement.

Output:

Enter three numbers to compare.
First Number: 32
Second Number: 65
Third Number: 19

Largest number: 65


Using Ternary operator

The ternary operator works like an if..else statement in C. Syntax of the ternary operator. (?:)

variable num1 = (expression) ? value if true : value if false

Output:

Enter three numbers to compare.
First Number: 45
Second Number: 98
Third Number: 66

Largest of three is: 98


MORE

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …
Read More

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …
Read More

Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …
Read More

Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …
Read More

Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …
Read More

Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …
Read More