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


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


List is :a b c => c

List is :A b C => b


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

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

int main() {

    char a, b, c;

    cout << "Enter Three Characters :";
    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 Characters :A B C
Largest is :C