Table of Contents
C++ program to check whether a character is an Alphabets or Not
In this article, we will discuss the concept of C++ program to check whether a character is an Alphabets or Not
In this post, we are going to learn how to write a program to check whether given character is English alphabet or not using various ways in C++ language
Code to check character is Alphabet or Not
Code to check the character is Alphabet or Not using if-else
In this code, we are going to learn how to check the given character is English alphabet or not using if- else statements in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { char ch;//declare a character variable //Ask to enter the character from user cout<<"enter a character as you wish\n"; //Storing the entered character in variable ch cin>>ch; if((ch>='A' && ch<='Z')||(ch>='a' && ch<='z')){ cout<< ch<<" is an Alphabet: "<< endl; // If the character is an alphabet, it displays } else { cout<< ch<<" is not an Alphabet: "<< endl; }// If the character is not an alphabet, it displays getch(); return 0; }
When the above code is executed, it produces the following result
Case 1
Enter a character as you wish N N is an Alphabets
Case 2
Enter a character as you wish d d is an Alphabets
Case 3
Enter a character as you wish @ @ is not an Alphabets
Code to check the character is Alphabet or Not using Ascii value
In this code, we are going to learn how to check the given character is English alphabet or not using Ascii value in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { char ch;//declare a character variable //Ask to enter the character from user cout<<"enter a character as you wish\n"; //Storing the entered character in variable ch cin>>ch; if((ch>=97 && ch<=122)||(ch>=65 && ch<=90)){ cout<< ch<<" is an Alphabet: "<< endl; // If the character is an alphabet, it displays } else { cout<< ch<<" is not an Alphabet: "<< endl; }// If the character is not an alphabet, it displays getch(); return 0; }
When the above code is executed, it produces the following result
Case 1
Enter a character as you wish h h is an Alphabets
Case 2
Enter a character as you wish Q Q is an Alphabets
Case 3
Enter a character as you wish + + is not an Alphabets
Code to check the character is Alphabet or Not using isalpha()
In this code, we are going to learn how to check the given character is English alphabet or not using isalpha() function in C++ language
Program 3
#include <iostream> #include <conio.h> using namespace std; int main() { char ch; cout << "Enter a character: " << endl; cin>>ch; if(isalpha(ch)){ cout <<ch<<" is an Alphabet" << endl; } else{ cout <<ch<< "is not an Alphabet " << endl; } getch(); return 0; }
When the above code is executed, it produces the following result
Case 1
Enter a character: E E is an Alphabet
Case 2
Enter a character: j j is an Alphabet
Case 3
Enter a character: * * is not an Alphabet
Suggested post
Similar post
Java program to print all alphabets in given range
C program to print all alphabets in given range
C++ program to print all alphabets in given range
Java program to print all alphabets using loops
C program to print all alphabets using loops
C++ program to print all alphabets using loops
Java program to check whether a character is Alphabet or Not
C++ program to check whether a character is Alphabet or Not
C program to check whether a character is Alphabet or Not
Python program to check whether a character is Alphabet or Not