

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C Program to check the type of character entered
Write a program to find out that a given character is upper case, lower case, number or special character.
Solution
- If an entered character is capital letter then, it displays the upper case.
Example: Input =H Output: upper case letter
- If an entered character is small letter then, it displays the lower case letter.
Example: Input= g Output: lower case letter
- If an entered character is number then, it displays the digit.
Example: Input=3 Output: digit
- If an entered character is a special character then, it displays the special character.
Example: Input= & Output: special character
Algorithm
Refer an algorithm given below to find out that a given character is upper case, lower case, number or special character.
Step 1 − Read input character from console at runtime.
Step 2 − Compute ASCII value of the character.
Step 3 − If the ASCII value of the character is in the range of 65 and 90, Then, print "Upper Case letter".
Step 4 − If the ASCII value of the character is in the range of 97 and 122, Then, print "Lower Case letter".
Step 5 − If the ASCII value of the character is in the range of 48 and 57, Then, print "Number".
Step 6 − Else, print "Symbol".
Example
Following is the C program to find out that a given character is upper case, lower case, number or special character −
#include<stdio.h> int main(){ char ch; printf("enter a character:"); scanf("%c",&ch); if(ch >= 65 && ch <= 90) printf("Upper Case Letter"); else if(ch >= 97 && ch <= 122) printf("Lower Case letter"); else if(ch >= 48 && ch <= 57) printf("Number"); else printf("Symbol"); return 0; }
Output
When the above program is executed, it produces the following output −
Run 1: enter a single character:45 Number Run 2: enter a character:# Symbol Run 3: enter a character:M Upper Case Letter
- Related Questions & Answers
- C program to find type of array entered by the user.
- Java Program to check whether the entered character is ASCII 7 bit numeric and character
- Java Program to check whether the entered value is ASCII 7-bit control character
- Java Program to check whether the entered character a digit, white space, lower case or upper case character
- C program for testing the character type
- C program to find array type entered by user using pointers.
- C# Program to display the Factors of the Entered Number
- Write a C# program to check if the entered number is Armstrong number?
- C# program to display factors of entered number
- C# Program to Check Whether the Entered Number is an Armstrong Number or Not
- C# Program to check if a character is a whitespace character
- Java Program to check whether the entered value is ASCII 7 bit alphabetic
- C++ Program to Print Number Entered by User
- C# Program to Count the Number of 1's in the Entered Numbers
- Type difference of character literals in C and C++