C Program to check whether given character is a digit or a alphabet - IProgramX

Q. Write a program to check whether given character is a digit or a character is lowercase or uppercase alphabet. (Hint ASCII value of digit is between 48 to 58 and Lowercase character shave ASCII values in the range of 97 to 122, uppercase is between 65 and 90) 



Program

#include <stdio.h>
int main()
{
    char ch;
    printf("Enter any character: ");
    scanf("%c", &ch);
    if(ch >= 'A' && ch <= 'Z')
    {
        printf("'%c' is uppercase alphabet.", ch);
    }
    else if(ch >= 'a' && ch <= 'z')
    {
        printf("'%c' is lowercase alphabet.", ch);
    }
    else if(ch>=0 && ch<=9)
    {
        printf("'%c' is not an alphabet.", ch);
    }
}

Output:

Enter any character: T
'T' is uppercase alphabet.

Post a Comment

0 Comments