C++ Nested if statement

C++ Nested if statement

June 22, 2024·İbrahim Korucuoğlu
İbrahim Korucuoğlu

In this article, we share an example showing C++ nested if statement.

#include <iostream>

using namespace std;

int main() {
/* nested if else statement */
    int a;
    cout << "Enter a positive integer number: ";
    cin >> a;
    if (a < 20) {
        cout << "a is less than 20\n";
        if (a < 10)
            cout << "a is less than 10\n";
        else
            cout << "a is not less than 10\n";
    } else {
        if (a == 20) {
            cout << "a is equal to 20\n";
        } else
            cout << "a is greater than 20\n";
    }
    return 0;
}
Last updated on