Write A C++ Program To Print Check Whether A Character Is An Alphabet or Not
Write A C++ Program To Print Check Whether A Character Is An Alphabet or Not
The ASCII value of the lowercase alphabet is from 97 to 122. And, the
ASCII value of the uppercase alphabet is from 65 to 90.
If the ASCII value of the character entered by the user lies in the range of
97 to 122 or from 65 to 90, that number is an alphabet.
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
printf("%c is an alphabet.", c);
else
printf("%c is not an alphabet.", c);
return 0;
}
Run Code
Output
Enter a character: *
* is not an alphabet
In the program, 'a' is used instead of 97 and 'z' is used instead of 122 .
if (isalpha(c))
printf("%c is an alphabet.", c);
else
printf("%c is not an alphabet.", c);