Write a Programme to Accept a character. Display a message stating whether it is an uppercase alphabet, or lowercase alphabet, or a digit, or a special character.
Answers
All characters whether alphabet, digit or special character have ASCII value. Input character from the user will determine if it’s Alphabet, Number or Special character.
ASCII value ranges-
For capital alphabets 65 – 90
For small alphabets 97 – 122
For digits 48 – 57
All other cases are Special Characters.
Examples :
Input : 8
Output : Digit
Input : E
Output : Alphabet
Recommended: Please try your approach on {IDE} first, before moving on to the solution.
// CPP program to find type of input character
#include <iostream>
using namespace std;
void charCheck(char input_char)
{
// CHECKING FOR ALPHABET
if ((input_char >= 65 && input_char <= 90)
|| (input_char >= 97 && input_char <= 122))
cout << " Alphabet ";
// CHECKING FOR DIGITS
else if (input_char >= 48 && input_char <= 57)
cout << " Digit ";
// OTHERWISE SPECIAL CHARACTER
else
cout << " Special Character ";
}
// Driver Code
int main()
{
char input_char = '$';
charCheck(input_char);
return 0;
}
Output :
Special Character
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.