This program is much similar to the previous one but here we are checking whether the given character is an alphabet, digit or a special character.

Logic

Here first we are checking whether the given character is an alphabet or not. If not then check in range 48 (0) to 57 (9) for digit, if it is neither alphabet nor digit then it is absolutely a special character.

See how it is working

Program

#include <iostream>

using namespace std;

int main() {

    char ch;

    cout << "Enter any character : ";
    cin >> ch;

    if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {

        cout << endl << ch << " is ALPHABET.";

    } else if(ch >= '0' && ch <= '9') {

        cout << endl << ch << " is DIGIT.";

    } else {

        cout << endl << ch << " is SPECIAL CHARACTER.";

    }

    return 0;
}

Output

Enter any character : #
# is SPECIAL CHARACTER.