
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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 Articles
- Java Program to check whether the entered character is ASCII 7 bit numeric and character
- C program to find type of array entered by the user.
- 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 to find array type entered by user using pointers.
- C program for testing the character type
- Write a C# program to check if the entered number is Armstrong number?
- C# Program to Check Whether the Entered Number is an Armstrong Number or Not
- C# Program to display the Factors of the Entered Number
- C# Program to check if a character is a whitespace character
- C# program to display factors of entered number
- Java Program to check whether the entered value is ASCII 7 bit alphabetic
- C++ Program to Print Number Entered by User
- Java Program to check whether the entered value is ASCII 7-bit alphabetic lowercase
- Java Program to check whether the entered value is ASCII 7 bit alphabetic uppercase
