C++ Nested if statement

Estimated read time 1 min read

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;
}
İbrahim Korucuoğlu

Yazar, bilişim ve teknoloji alanında derlediği faydalı içerikleri bu blogta paylaşmaktadır.