Largest of Three Numbers in C

In this quick article, we are going to learn about a simple C program, in which we are given three numbers, and we need to find the largest of those numbers. The C program for this is really simple, provided that you already understand the logic behind this program, which will be discussed in this article.

Largest of Three Numbers in C

When you are given three numbers, and you need to find the largest of those three numbers, you can simply make use of the if-else statements, or even the ternary operator.

In the below-given video below, you can find a detailed explanation and program for finding the largest of the three given numbers. After watching the video, you can also do this simple program, and get the largest of three numbers.

Here is the simple C program to get the largest of three given numbers –

#include <stdio.h>

int main() {
int num1, num2, num3;
printf(“Please Enter the three numbers:”);
scanf(“%d”, &num1);
scanf(“%d”, &num2);
scanf(“%d”, &num3);

if ((num1 > num2) && (num1 > num3))
printf(“%d is the largest numbern”, num1);
else if (num2 > num3)
printf(“%d is the largest numbern”, num2);
else
printf(“%d is the largest numbern”, num3);

return 0;
}

Program Output 1 –
Please Enter the three numbers:140 8 366
366 is the largest number

Program Output 2 –
Please Enter the three numbers:1120 12 255
1120 is the largest number

Program Output 3 –
Please Enter the three numbers:145 158 147
158 is the largest number