In this tutorial you will learn about the C Program to Check Character is Alphabet Digit or Special Character and its application with practical example.
C Program to Check Character is Alphabet Digit or Special Character
In this tutorial, we will learn to create a C program that will Check the Character is Alphabet Digit or Special Character in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Conditional Statements in C programming.
What is a character?
The character is a single entity in the English language or in any word. These characters can be anything alphabets, digits, special symbols,
For Example:-
In the word “W3Adda@”, there are six characters, they are as follows
- “W”
- “3”
- “A”
- “d”
- ‘d’
- ‘a’
- ‘@’
Here,
“W” is an alphabet.
“3” is a digit.
“A, d, d, a” are also alphabets.
“@” is a Special Character.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 12 |
1. Declaring the variables for the program. 2. Taking the input character from the user. 3. Passing those variables to conditional statements. 4. Using those conditions to find the type of character means digits, alphabets, special characters. 5. Printing the result. 6. End Program. |
Program to check Character is Alphabet Digit or Special Character
First, we will take the input character from the user. Then will pass that character in the conditional statements to find whether the character is the alphabet, digit, special character.
With the help of this program, we can Check the Character with the conditions.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
/** * C program to check alphabet, digit or special character */ #include <stdio.h> int main() { /* Declaring the variable required for the program */ char chr; /* Input character from user */ printf("Enter any character: "); scanf("%c", &chr); /* Checking the Alphabet if it is alphabet digit or special character. */ if((chr >= 'a' && chr <= 'z') || (chr >= 'A' && chr <= 'Z')) { /* Printing the output character as an alphabet */ printf("'%c' is alphabet.", chr); } else if(chr >= '0' && chr <= '9') { /* Printing the output character as a digit */ printf("'%c' is digit.", chr); } else { /* Printing the output character as a special character */ printf("'%c' is special character.", chr); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- chr = it will hold the character value for the input.
Input character from the user.
Checking the given character is an alphabet, digit, or special character.
Printing output for the program.