In this post, we will discuss the concept of C++ programming code to check whether the character is Alphabet or not
Here, we are going to learn how to find whether the given character is Alphabet or not in C++ programming language
What is ASCII
In the C++ programming language, all the character variables hold an ASCII value for computer usage.ASCII value is represented by integer values between 0 to 127.
The ASCII value of lowercase Alphabets are from 97 to 122 and The ASCII value of uppercase Alphabets are from 65 to 90
This concept is done using three ways
The program allows the user to enter a character thereafter it will check and display the result of the given character whether it is an alphabet or non-alphabet using the if-else statements in C++ programming language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { char ch; //Asking the user to enter the character cout<<"Enter a caracter 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: "; // If the character is an alphabet, it is displayed } else { cout<<ch<<" is not an Alphabet: "; }// If the character is not an alphabet, it is displayed getch(); return 0; }
When the above code is executed it produces the following result
Case 1
Enter a character as you wish X X is an Alphabet
Case 2
Enter a character as you wish d d is an Alphabet
Case 3
Enter a character as you wish & & is not an Alphabet
Approach
The program allows the user to enter a character thereafter it will check and display the result of the given character whether it is an alphabet or non-alphabet using the Ternary operator in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { char ch; //Ask input the character cout<<"Enter the character\n"; //Get the input and store the variable ch cin>>ch; (ch>='A' && ch<='Z')||(ch>='a' && ch<='z') ? cout<<"It is an Alphabet" : cout<<"It is not an Alphabet"; getch(); return 0; }
When the above code is executed it produces the following result
Case 1
Enter the character B It is an Alphabet
Case 2
Enter the character g It is an Alphabet
Case 3
Enter the character % It is not an Alphabet
Approach
The program allows the user to enter a character thereafter it will check and display the result of the given character whether it is an alphabet or non-alphabet using ASCII value
Program 3
#include <iostream> #include <conio.h> using namespace std; int main() { char ch; cout<<"Enter any character\n"; cin>>ch; if((ch>=97 && ch<=122)||(ch>=65 && ch<=90)){ cout<<ch<<" is an Alphabet"; } else { cout<<ch<<" is not an Alphabet"; } getch(); return 0; }
When the above code is executed it produces the following result
Case 1
Enter any character M M is an Alphabet
Case 2
Enter any character t t is an Alphabet
Case 3
Enter any character # # is not an Alphabet
Approach
The Alphabet has ASCII values between 65 to 90(capital letters) and 97 to 122 (small letters)
Suggested for you
Data type in C++ language
If-else statements in C++ Language
Similar post
C code to check whether the character is Alphabet or not
Java code to check whether the character is Alphabet or not
Python code to check whether the character is Alphabet or not
C code to check whether the Alphabet is vowel or consonant
C++ code to check whether the Alphabet is vowel or consonant
Python code to check whether the Alphabet is vowel or consonant
Java code to check whether the Alphabet is vowel or consonant
Java program to print all upper case and lower case Alphabets
C++ program to print all upper case and lower case Alphabets
C program to print all upper case and lower case Alphabets
Java code to print all upper case and lower case Alphabets between the given range
C++ code to print all upper case and lower case Alphabets between the given range
C code to print all upper case and lower case Alphabets between the given range
10 simple ways to add two numbers in Java In this article, we will discuss…
Write a Python program to find the first n prime numbers In this article we…
Python: Calculate Average of odd and even in a list using loops In this post,…
Python: Average of Odd & Even Numbers from User Input In this post, we will…
Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…
Python program to calculate the sum of odd and even numbers in a list In…