BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to check whether a Character is an Alphabet or not

Last Updated: July 15, 2022 by Chaitanya Singh | Filed Under: C Programs

In this tutorial, you will learn how to write a C program to check whether a character entered by user is an alphabet or not.

Example: Program to check whether a character is an Alphabet or not

In the following example, user is asked to enter a character, which is stored in a char variable ch. Once the value of entered character is captured using scanf() function, you can easily check whether its an alphabet or not by doing the following check in if statement.

For lowercase alphabets: >= ‘a’ and <= ‘z’
For uppercase alphabets: >= ‘A’ and <= ‘Z’

If the input character lies in one of these ranges then the character is an alphabet else it’s not an alphabet.

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

  if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
    printf("Entered character %c is an alphabet.", ch);
  else
    printf("Entered character %c is not an alphabet.", ch);

  return 0;
}

Output:
When the entered character is ‘A’
C Program to Check Whether a Character is an Alphabet or not

When the entered character is 9
C Program to Check Whether a Character is an Alphabet or not

You can also check the alphabet using the ASCII values of characters like this:

if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))
   printf("The entered character %c is an Alphabet",ch);
else
   printf("The entered character %c is not an Alphabet",ch);

The ASCII value of ‘a’ is 97, ‘z’ is 122, ‘A’ is 65 and ‘Z’ is 90.

Related C Examples:

  • C Program to check whether an alphabet is vowel or consonant
  • C Program to find ASCII value of a Character
  • C Program to sort set of strings in alphabetical order
  • C Program to reverse a string
❮ C TutorialC Programs ❯

Top Related Articles:

  1. C Program to concatenate two strings without using strcat
  2. C Program to Multiply two Floating Point Numbers
  3. C Program to Swap two numbers
  4. C program to replace first occurrence of vowel with ‘-‘ in string
  5. C Program to calculate Area of an Equilateral triangle

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

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

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap