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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.