C++ Program to find largest of three numbers using nested if


In this Example, You will learn how to find largest of three numbers using nested if statement in C++.


List is :10 20 40 => 40

List is :30 20 10 => 30


Example: How to find largest of three numbers using nested if statement in C++

Run it Now
#include<iostream>
using namespace std;

int main() {

    int a, b, c;

    cout << "Enter Three numbers :";
    cin >> a >> b >> c;

    if (a > b) {
        if (a > c) {
            cout << "\nLargest is :" << a;
        } else {
            cout << "\nLargest is :" << c;
        }
    } else {
        if (b > c) {
            cout << "\nLargest is :" << b;
        } else {
            cout << "\nLargest is :" << c;
        }
    }

    return 0;
}

Output:

Enter Three numbers :10 20 30
Largest is :30