Write a program to find if a character entered by user is upper case or lower case.
// program to find if a character entered by user is upper case or lower case.
#include<Stdio.h>
int main()
{
char ch;
printf("enter character\n");
scanf("%c", &ch);
if(ch >= 'A' && ch <= 'Z'){
// In, ASCII value every character have its integer value
// ASCII value of A = 65 and Z = 90
printf("upper case");
}
else if(ch >= 'a' && ch <= 'z')
{
printf("lower case");
}
else{
printf("invalid character");
}
return 0;
}
Output :
enter character
G
upper case
--------------------------------
Process exited after 7.554 seconds with return value 0
Press any key to continue . .
enter character
g
lower case
--------------------------------
Process exited after 7.554 seconds with return value 0
Press any key to continue . .
enter character
#
invalid character
--------------------------------
Process exited after 7.554 seconds with return value 0
Press any key to continue . .
Comments
Post a Comment
Please do not enter any spam link in the comment box.