In this tutorial you will learn about the C Program to check character is a digit or not using IsDigit function 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 |
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 check the given character is digit or not. 5. Printing the result. 6. End Program. |
Program to check character is a digit or not using IsDigit function
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 digit or not without using the isdigit function.
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 |
/** * C program to check character is a digit or not using IsDigit function */ #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 character if it is digit or not without using the isdigit function. */ 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 not a digit .", chr); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- chr = it will hold the input value.
Input character from the user.
Checking the given character is digit or not.
Printing output for the program.