Check if a character is alphabet - C++ Program

Q. Write a C++ program to check whether the entered character is an alphabet or not.

Answer:

Following program shows that whether the entered character is an alphabet or not. You can also use ASCII values of character to check for an alphabet. If character has ASCII values between 65 to 92 or 97 to 122, it will be an alphabet. Otherwise, it will be not an alphabet.

#include<iostream>
using namespace std;
int main()
{
        char ch;
        cout<<"Enter a Character: \n ";
        cin>>ch;
        if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
        {
                cout<<ch<<" is an Alphabet";
        }
        else
        {
                cout<<ch<<" is Not an Alphabet";
        }
        return 0;
}


Output:

check alphabet