C Program to check whether the Character is Alphabet or Not

Write a C Program to check whether the Character is Alphabet or Not by using the Built-in function isalpha and not using isalpha() function.

C Program to check whether the Character is Alphabet or Not

This C program allows the user to enter one character. Then it will check whether the input character is Alphabet or not.

#include <stdio.h>

int main()
{
  char ch;
  printf("\n Please Enter any character \n");
  scanf("%c", &ch);
  
  if( (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') )
    printf("\n %c is an Alphabet", ch);
  else
    printf("\n %c is not an Alphabet", ch);
  
  return 0;
}

Let us check whether S is an Alphabet or not (TRUE)

C Program to check whether the Character is Alphabet or Not output 1

Within this C Program to check the Character is Alphabet or Not example, the first printf statement will ask the user to enter any character. Next, the character will assign to variable ch.

if( (ch >= ‘a’ && ch <= ‘z’) || (ch >= ‘A’ && ch <= ‘Z’))

Within the C program If statement, the First condition (ch >= ‘a’ && ch <= ‘z’) will check whether the character entered by the user is between a and z. The second condition (ch >= ‘A’ && ch <= ‘Z’) will check whether the character entered by the user is between A and B.

  • If one of those conditions is TRUE, the character entered by the user is an Alphabet.
  • If both of the above conditions is FALSE, the character entered by the user is Not an Alphabet.

C Program to check whether the Character is Alphabet or Not Method 2

This program uses the ASCII values of a character. Then checks whether the input character is Alphabet or not.

#include <stdio.h>

int main()
{
  char ch;
  printf("\n Please Enter any character \n");
  scanf("%c", &ch);
  if( (ch >= '65' && ch <= '90')|| (ch >= '97' && ch <= '122'))
    printf("\n %c is an Alphabet", ch);
  else
    printf("\n %c is not an Alphabet", ch);
 return 0;
}

Let us check whether g is an Alphabet or not (TRUE)

 Please Enter any character 
g

 g is not an Alphabet

When we store a character into the memory, instead of storing the character the memory will store the ASCII value of that character.

For example, the ASCII value of A = 65. So, in the C Program to check the Character is Alphabet or Not program, we tested against the ASCII value instead of character.

The first C Programming printf statement will ask the user to enter any character, and the character assigned to variable ch.

if( (ch >= ’65’ && ch <= ’90’)|| (ch >= ’97’ && ch <= ‘122’))

Within the If statement, the first condition (ch >= ‘65’ && ch <= ‘90’) checks whether the character entered by the user is between A and B. The second condition (ch >= ‘97’ && ch <= ‘122’) checks whether the character is between a and b.

  • If one of those conditions is TRUE, the character entered by the user is an Alphabet.
  • If both of them are FALSE, the character entered by the user is Not an Alphabet.

Program to check whether the Character is Alphabet or Not using isalpha Function

This C program check whether the input character is Alphabet or not using one of the built-in function isapha

#include <stdio.h>
#include<ctype.h>

int main()
{
  char ch;
  
  printf("\n Please Enter any character \n");
  scanf("%c", &ch);
  
  if( isalpha(ch) )
    printf("\n%c is an Alphabet", ch);
  else
    printf("\n %c is not an Alphabet", ch);
  
  return 0;
}

In this C Program to find the Character is Alphabet or Not example

  • isalpha(ch) function check whether the given character (ch) is Alphabet or not.
  • If the condition isalpha(ch) is TRUE, the character is an Alphabet.
  • If the condition isalpha(ch) is FALSE, the character is Not an Alphabet.

Let us check whether M is an Alphabet or not (TRUE)

 Please Enter any character 
M

M is an Alphabet

Let us check whether 6 is an Alphabet or not (Which is FALSE)

 Please Enter any character 
6

 6 is not an Alphabet