Check character is alphabet in C++
if else - Question 11
In this question, we will see how to check if a character is an alphabet or not in C++ programming using the if else statement. To know more about if else statement click on the if else statement lesson.
Q11) Write a program in C++ to input a character and check if it is an alphabet or not. Make use of logical operators (&& ||) to solve this question.
Program
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
char x;
cout<<"Enter a character ";
cin>>x;
if((x>='A' && x<='Z') || (x>='a' && x<='z'))
{
cout<<"Its an alphabet";
}
else
{
cout<<"Its not an alphabet";
}
return 0;
}
Output
Enter a character G Its an alphabet