0% found this document useful (0 votes)
23 views2 pages

Write A C++ Program To Print Check Whether A Character Is An Alphabet or Not

e

Uploaded by

Ajay kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Write A C++ Program To Print Check Whether A Character Is An Alphabet or Not

e

Uploaded by

Ajay kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

6.

Write a C++ Program to Print


Check Whether a Character is
an Alphabet or Not

C Program to Check Whether a


Character is an Alphabet or not
To understand this example, you should have the knowledge of the
following C programming topics:
 C Programming Operators
 C if...else Statement

In C programming, a character variable holds an ASCII value (an integer


number between 0 and 127) rather than that character itself.

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.

Program to Check Alphabet


#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);

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 .

Similarly, 'A' is used instead of 65 and 'Z' is used instead of 90 .

Note: It is recommended we use the isalpha() function to check whether a


character is an alphabet or not.

if (isalpha(c))
printf("%c is an alphabet.", c);
else
printf("%c is not an alphabet.", c);

You might also like