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

C Program to search an element in an array using Pointers

A separate function( search_function()) will be created where the array pointer will be declared and the searched element along with the size of an array …

C Program to find the sum of the digits of a number using recursion function

This C program calculates the sum of digits of a given number using recursion. Here’s a concise explanation: Function Definition: sumDigits(int n) This function calculates …

C program to find factorial of a number using Ternary operator with Recursion

Recursion refers to the function calling itself directly or in a cycle. Before we begin, you should have the knowledge of following in C Programming: …

C Program to Add Two Numbers Using Call by Reference

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through …

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 …

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 …