C++ Program to find the 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 the largest of three characters using nested if in C++.

#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 << "Largest is:" << a;
        } else {
            cout << "Largest is:" << c;
        }
    } else {
        if (b > c) {
            cout << "Largest is:" << b;
        } else {
            cout << "Largest is:" << c;
        }
    }

    return 0;
}

Output:

Enter three characters:a b c
Largest is:c