In C programming, the largest element of a number is the number with the highest numerical value of the three numbers.

For example, if three numbers are given, 1, 2, 3, the largest of the three numbers is 3.

Problem Description

Write a C program that takes the 3 numbers and finds the largest number Aamong three numbers.

Problem Solution

Alorithm:

1. Take the three numbers as input and store them in variables.

2. Check the first number if it is greater than other two.

3. Repeat the step 2 for other two numbers.

4. Print the number which is greater among all and exit.

There are several ways to find the largest number among three numbers in C language. Let’s take a detailed look at all the approaches to find the largest/biggest of 3 numbers.

Method 1: (Using If Statement)

In this approach, we will calculate the largest of three numbers using if statement.

Example:

Input:

Enter three numbers:

a = 6; b = 8; c = 10

Step 1: Check if (a > b && a > c) i.e if(6 > 8 && 6 > 10). Since 6 is not greater than 8 and 10, so go to the next condition.

Step 2: Check if (b > a && b > c) i.e if(8 > 6 && 8 > 10). Here 8 is greater than 6, but 8 > 10 does not satisfy the condition, so we move on to the next condition.

Step 3: Check if (c > a && c > b) i.e if(10 > 6 && 10 > b). Since 10 is greater than 6 and 8, so the largest number is 10.

Output:

Biggest number is 10

/*

* C program to find the largest of three numbers

*/

#include

int main()

{

int a, b, c;

printf(“Enter three numbers: \na: “);

scanf(“%d”, &a);

printf(“b: “);

scanf(“%d”, &b);

printf(“c: “);

scanf(“%d”, &c);

if (a > b && a > c)

printf(“Biggest number is %d”, a);

if (b > a && b > c)

printf(“Biggest number is %d”, b);

if (c > a && c > b)

printf(“Biggest number is %d”, c);

return 0;

Runtime Test Cases

Testcase 1: In this case, we enter the values ”6, 8 and 10” as input to find the largest of the three given numbers.

Enter three numbers:

a: 6

b: 8

c: 10

Biggest number is 10

Testcase 2: In this case, we enter the values ”10, 99 and 87” as input to find the largest of the three given numbers.

Enter three numbers:

a: 10

b: 99

c: 87

Biggest number is 99