C++ Program to check whether a character is uppercase, lowercase ,digit or special character
Character is uppercase ,lowercase ,digit or special character
Here we will discuss C++ program to check whether a character is uppercase, lowercase ,digit or special character. As there are different types of character in C++, so we’ll learn to write a code to do so.
Program to check whether a character is uppercase, lowercase ,digit or special character
In C++ programming language a char type variable can store many different types of values ,128 values in total, single value at a time. Each value has been assigned a code by which they can be identified and that is called ASCII code.
- Alphabets
- Uppercase( between 65 to 90 )
- Lowercase( between 97 to 122)
- Digits (between 48 to 57)
- Special Characters (all the remaining in between 0 to 127)
Working:
- User gives an input.
- The input is stored in a char type variable say prep.
- prep is then checked using the if else-if statement.
- For uppercase alphabets
if((prep >= 65) && (prep <= 90))
- For lowercase alphabets
else if((prep >= 97) && (prep <= 122))
- For digits
else if((prep >= 48) && (prep <= 57))
- All others will be the special characters.
C++ code
Run
//C++ program //Character is alphabet, a digit, or a special character #include <iostream> using namespace std; int main() { char charCheck; cout<<"Enter a character: "; cin>>charCheck; //for uppercase alphabets if((charCheck >= 65) && (charCheck <= 90)) { cout<<charCheck<<" is Uppercase Alphabet"; } // for lowercase alphabets else if((charCheck >= 97) && (charCheck <= 122)) { cout<<charCheck<<" is Lowercase Alphabet"; } //for digits else if((charCheck >= 48) && (charCheck <= 57)) { cout<<charCheck<<" is a Digit"; } //all remaining are special characters else { cout<<charCheck<<" is a Special Character"; } return 0; }
Output:
Enter a character: @ @ is a Special Character
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Getting Started
- Positive or Negative number: C | C++ | Java | Python
- Even or Odd number: C | C++ | Java | Python
- Sum of First N Natural numbers: C | C++ | Java | Python
- Sum of N natural numbers: C | C++ | Java | Python
- Sum of numbers in a given range: C | C++ | Java | Python
- Greatest of two numbers: C | C++ | Java | Python
- Greatest of the Three numbers: C | C++ | Java | Python
- Leap year or not: C | C++ | Java | Python
- Prime number: C | C++ | Java | Python
- Prime number within a given range: C | C++ | Java | Python
- Sum of digits of a number: C | C++ | Java | Python
- Reverse of a number : C | C++ | Java | Python
- Palindrome number: C | C++ | Java | Python
- Armstrong number : C | C++ | Java | Python
- Armstrong number in a given range : C | C++ | Java | Python
- Fibonacci Series upto nth term : C | C++ | Java | Python
- Find the Nth Term of the Fibonacci Series : C | C++ | Java | Python
- Factorial of a number : C | C++ | Java | Python
- Power of a number : C | C++ | Java | Python
- Factor of a number : C | C++ | Java | Python
- Finding Prime Factors of a number : C | C++ | Java | Python
- Strong number : C | C++ | Java | Python
- Perfect number : C | C++ | Java | Python
- Automorphic number : C | C++ | Java | Python
- Harshad number : C | C++ | Java | Python
- Abundant number : C| C++ | Java | Python
- Friendly pair : C | C++ | Java | Python
Login/Signup to comment