Algorithm


a and A both are different and have different ASCII values.

Step by step descriptive logic to check alphabets.

  1. Input a character from user. Store it in some variable say ch.
  2. Check if((ch >= 'a') && (ch <= 'z')) or if((ch >= 'A') && (ch <= 'Z')).
  3. Then it is alphabet otherwise not.

 

Code Examples

#1 Code Example-C Program to check alphabets

Code - C Programming

/**
 * C program to check whether a character is alphabet or not
 */

#include <stdio.h>

int main()
{
    char ch;
    
    /* Input a character from user */
    printf("Enter any character: ");
    scanf("%c", &ch);
    

    if((ch >= 'a' && ch lt;= 'z') || (ch >= 'A' && ch lt;= 'Z'))
    {
        printf("Character is an ALPHABET.");
    }
    else
    {
        printf("Character is NOT ALPHABET.");
    }

    return 0;
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter any character: b
Character is an ALPHABET.

#2 Code Exampl-C Programing to check alphabets using ASCII value

Code - C Programming

/**
 * C program to check whether a character is alphabet or not
 */

#include <stdio.h>

int main()
{
    char ch;

    /* Input a character from user */
    printf("Enter any character: ");
    scanf("%c", &ch);


    if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))
    {
        printf("Character is an ALPHABET.");
    }
    else
    {
        printf("Character is NOT ALPHABET.");
    }

    return 0;
}
Copy The Code & Try With Live Editor
Advertisements

Demonstration


C Programing Example to Check Whether a Character is an Alphabet or not-DevsEnv

Next
Appending into a File in C Programming