Dremendo Tag Line

Check character is alphabet in C

if else - Question 11

In this question, we will see how to check if a character is an alphabet or not in C programming using the if else statement. To know more about if else statement click on the if else statement lesson.

Q11) Write a program in C to input a character and check if it is an alphabet or not. Make use of logical operators (&& ||) to solve this question.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    char x;
    printf("Enter a character ");
    scanf("%c",&x);
    if((x>='A' && x<='Z') || (x>='a' && x<='z'))
    {
        printf("Its an alphabet");
    }
    else
    {
        printf("Its not an alphabet");
    }
    return 0;
}

Output

Enter a character G
Its an alphabet
video-poster