In this tutorial you will learn about the C Program to check Character is Alphabet or Digit and its application with practical example.
C Program to Check Character is Alphabet or Digit
In this tutorial, we will learn to create a C program that will Check the Character is Alphabet or Digit 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.
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.
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 find the type of character means digits and alphabets. 5. Printing the result. 6. End Program. |
Program to check Character is Alphabet or Digit
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 or digit.
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 |
/** * C Program to check Character is Alphabet or Digit */ #include <stdio.h> #include<ctype.h> int main() { //Declaring the required variable for the program. char ch; //Taking the input variable for the program. printf(" Please Enter any character : "); scanf("%c", &ch); //Checking the character from the input by the user. if (isalpha(ch)) { //Printing the output from the program to the user printf("\n %c is an Alphabet", ch); } else if (isdigit(ch)) { //Printing the output from the program to the user printf("\n %c is a Digit", ch); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- ch = it will hold the character value for the input.
Input character from the user.
Checking the given character is an alphabet, digit.
Printing output for the program.