Site icon T4Tutorials.com

C++ Nested If else Program Example

C++ Nested If else Program in which user enter 3 numbers, and then program will find greater number.

#include <iostream>
using namespace std;
int main() {
    int num1, num2, num3;
    // Input three numbers
    cout << "Enter three numbers: ";
    cin >> num1 >> num2 >> num3;
    // Nested if-else to find the greatest number
    if (num1 >= num2) {
        if (num1 >= num3)
            cout << num1 << " is the greatest number.";
        else
            cout << num3 << " is the greatest number.";
    } else {
        if (num2 >= num3)
            cout << num2 << " is the greatest number.";
        else
            cout << num3 << " is the greatest number.";
    }
    return 0;
}

 

Exit mobile version