beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

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

By Chaitanya Singh | Filed Under: C Programs

This program checks whether the character (entered by user) is an alphabet or not.

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

This program takes the character value (entered by user) and checks whether it lies between the following ranges:
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. To understand this program, you should have the knowledge of following C programming topic:

  • C Programming if else statement
#include <stdio.h>
int main()
{
    char ch;

    //Asking user to enter the character
    printf("Enter any character: ");
    //storing the entered character into the variable ch
    scanf("%c",&ch);

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

    return 0;
}

Output 1:

Enter any character: 9
The entered character 9 is not an Alphabet

Output 2:

Enter any character: P
The entered character P is an Alphabet

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.

Check out these related programs:

  1. C Program to check whether an alphabet is vowel or consonant
  2. C Program to find ASCII value of a Character
  3. C Program to sort set of strings in alphabetical order
  4. C Program to reverse a string
  5. C Program to concatenate two strings

Leave a Reply Cancel reply

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

Programs

  • C Programs
  • Java Programs

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap