Program to Check Whether a Character is Alphabet

Alphabet Characters:

We will write a basic C program to check whether a character is Alphabet or not. An alphabet is an english character from a to z. There should be no special character.

Program to check whether a program is alphabet

Working of Program :

In the program, we will require a character from user to check and some basic operators to perform the operstion.

Run
#include<stdio.h>

int main() {
    // Write C code here
    char ch;
    printf("Enter the character :");
    scanf("%c", &ch);
    
    if(ch >='a' && ch <= 'z' || ch >='A' && ch <= 'Z'){
        printf("Character is Alphabet");
        
    }
    else{
        printf("Character is not an Alphabet");
    }

    return 0;
}

Output :

Enter the character : a
a
Character is Alphabet

In the above program,

  • scanf will take the input from the user.
  • Condition inside the if block will check whether the character is alphabet or not.
  • printf will print the output on the screen

Example :

Let’s solve this problem by typecasting method

Run
#include<stdio.h>
int main()
{
    char ch;
    printf("Enter the character :");
    scanf("%c", &ch);
    if(ch >=32 && ch <=64 || ch >=97 && ch <= 122)
    {
        printf("Character is Alphabet");
    }
    else
    {
        printf("Character is not an Alphabet");
    }

    return 0;
}

Output :

Enter the character : a
a
Character is Alphabet

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription