# Find The Largest Among Three Numbers In C++

What we are going to see through this article is we will see in detail Find The Largest Among Three Numbers In C++. here are three methods available to find the largest number among three numbers in C++ language. Following are the three methods.

• Using if statement
• Using if … else statement
• Using Nested if statement

## Type 1: Find the Largest Among Three Numbers Using if Statement

``````#include <iostream>
using namespace std;

int main() {
float n1, n2, n3;

cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;

if(n1 >= n2 && n1 >= n3)
cout << "Largest number: " << n1;

if(n2 >= n1 && n2 >= n3)
cout << "Largest number: " << n2;

if(n3 >= n1 && n3 >= n2)
cout << "Largest number: " << n3;

return 0;
}``````

## Output

``````Enter three numbers: 2.3
8.3
-4.2
Largest number: 8.3``````

## Type 2 : Find the Largest Among Three Numbers Using if…Else Statement

Two if..else condition is used to check which number is largest among the three numbers.

``````#include <iostream>
using namespace std;

int main() {
float n1, n2, n3;

cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;

if((n1 >= n2) && (n1 >= n3))
cout << "Largest number: " << n1;
else if ((n2 >= n1) && (n2 >= n3))
cout << "Largest number: " << n2;
else
cout << "Largest number: " << n3;

return 0;
}``````

## Output

``````Enter three numbers: 2.3
8.3
-4.2
Largest number: 8.3``````

Read Also: Remove Punctuations From A String In C++

## Type 3 : Find the Largest Among Three Numbers Using Nested if Statement

``````#include <iostream>
using namespace std;

int main() {
float n1, n2, n3;

cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;

if (n1 >= n2) {
if (n1 >= n3)
cout << "Largest number: " << n1;
else
cout << "Largest number: " << n3;
}
else {
if (n2 >= n3)
cout << "Largest number: " << n2;
else
cout << "Largest number: " << n3;
}

return 0;
}``````

## Output

``````Enter three numbers: 2.3
8.3
-4.2
Largest number: 8.3``````