C Program To Check Whether a Character is an Alphabet or Not


Lets write a C program to check if user input character is an alphabet or not.

Related Read:
Relational Operators In C
Logical Operators In C

Note: In C programming language, every character variable holds an ASCII value rather than the character itself. You can check ASCII value of all the characters here: C Program To Print All ASCII Characters and Code

Also watch video tutorial: C Program to Print ASCII Value of a Character

Note: ASCII value range of lower case alphabets:
ASCII value of a is 97.
ASCII value of b is 98.
ASCII value of c is 99.
and so on till z ..
ASCII value of z is 122.

ASCII value range of upper case alphabets:
ASCII value of A is 65.
ASCII value of B is 66.
ASCII value of C is 67.
and so on till z ..
ASCII value of Z is 90.

Source Code: C Program To Check Whether a Character is an Alphabet or Not

#include < stdio.h >

int main()
{
    char c;

    printf("Enter a character\n");
    scanf("%c", &c);

    if( (c >= 'a' && c <= 'z') ||
        (c >= 'A' && c <= 'Z') )
    {
        printf("%c is an alphabet\n", c);
    }
    else
    {
        printf("%c is not an alphabet\n", c);
    }

    return 0;
}

Output 1:
Enter a character
5
5 is not an alphabet

Output 2:
Enter a character
a
a is an alphabet

Output 3:
Enter a character
$
$ is not an alphabet

Output 4:
Enter a character
S
S is an alphabet

Output 5:
Enter a character
#
# is not an alphabet

Logic To Check Whether a Character is an Alphabet or Not

We accept the character from user as input. We check if the user entered character is greater than or equal to a and less than or equal to z OR the user entered character is greater than or equal to A and less than or equal to Z. If these conditions are met, then user entered character is an alphabet or else its not.

Video Tutorial: C Program To Check Whether a Character is an Alphabet or Not


[youtube https://www.youtube.com/watch?v=uY3d6SXBBNE]

YouTube Link: https://www.youtube.com/watch?v=uY3d6SXBBNE [Watch the Video In Full Screen.]

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

Your email address will not be published. Required fields are marked *