Given a letter X. Determine whether X is Digit or Alphabet and if it is Alphabet determine if it is Capital Case or Small Case.
Note:
- Digits in ASCII '0' = 48,'1' = 49 ....etc
- Capital letters in ASCII 'A' = 65, 'B' = 66 ....etc
- Small letters in ASCII 'a' = 97,'b' = 98 ....etc
Only one line containing a character X which will be a capital or small letter or digit.
Print a single line contains "IS DIGIT" if X is digit otherwise, print "ALPHA" in the first line followed by a new line that contains "IS CAPITAL" if X is a capital letter and "IS SMALL" if X is a small letter.
A
ALPHA
IS CAPITAL
9
IS DIGIT
a
ALPHA
IS SMALL
** recommended to read this to know more about ASCII Code https://www.javatpoint.com/ascii.
my code:
#include<iostream>
using namespace std;
int main()
{
char ch;
cin >> ch;
if (ch >= 65 && ch <= 90)
{
cout << "ALPHA\n";
cout << "IS CAPITAL\n";
}
else if (ch >= 97 && ch <= 122)
{
cout << "ALPHA\n";
cout << "IS SMALL\n";
}
else
{
cout << "IS DIGIT\n";
}
return 0;
}
No comments:
Post a Comment