Program is accepting any character from user. We compare user input with ASCII value of A to Z or a to z. ASCII value of lower case a to z start from 97 to 122. ASCII value of uppercase A to Z start from 65 to 90.
/******************************************************************
Program Name: Write program to check whether given character is a
digit or character in lowercase or uppercase alphabet without using any function
**********************************************************/
#include<stdio.h>
#include<conio.h>
void main()
{
//variable declaration to store user input
char ch;
//ASCII value of a to z is between 97 to 122
//ASCII value of A to Z is between 65 to 90
printf("\n\tEnter Character : ");
ch=getchar();
if((ch>=48)&&(ch<=57))
{
printf("\n\t %c is integer ",ch);
}
else
{
if((ch>=97)&&(ch<=122))
printf("\n\t '%c' is Lowercase alphabet character ",ch);
else
{
if((ch>=65)&&(ch<=90))
printf("\n\t '%c' is Uppercase alphabet character ",ch);
else
printf("\n\t '%c' is not alphabet or number",ch);
}
}
getch();
}
Output
Enter Character : D
'D' is Uppercase alphabet character
Enter Character : d
'd' is Lowercase alphabet character
Enter Character : $
'$' is not alphabet or number
Enter Character : 1
1 is integer