codescracker


c++

C++ Program to Check Alphabet or Not



« Previous Program Next Program »


Check Alphabet or Not in C++

To check whether the entered character is an alphabet or not alphabet in C++ programming, you have to ask to the user to enter a character and start checking for alphabet. To check for alphabet, use ASCII values of character, if character has ASCII values between 65 to 92 or 97 to 122 then it will be an alphabet. Otherwise, it will not be an alphabet. You can also check whether the character is in between a to z(alphabet) or A to Z(alphabet). Otherwise, not an alphabet as shown here in the following program.

C++ Programming Code to Check Alphabet or Not

Following C++ program ask to the user to enter a character to check whether it is an alphabet or not, then display the output on the screen:

/* C++ Program - Check Alphabet or Not */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	char ch;
	cout<<"Enter a character: ";
	cin>>ch;
	if((ch>='a'&& ch<='z') || (ch>='A' && ch<='Z'))
	{
		cout<<ch<<" is an alphabet";
	}
	else
	{
		cout<<ch<<" is not an alphabet";
	}
	getch();
}

When the above C++ program is compile and executed, it will produce the following result. Above C++ Programming Example Output (alphabet - lowercase):

C++ program check alphabet

Above C++ Programming Example Output (alphabet - uppercase):

C++ program alphabet

Above C++ Programming Example Output (not alphabet - number):

alphabet C++ program

Above C++ Programming Example Output (not alphabet - special character):

alphabet program c++

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test