- 0
Notifications Mark All Read
- Login
- Get Prime
Program to Check Whether a Character is Alphabet
Alphabet Characters:
We will write a basic C program to check whether a character is Alphabet or not. An alphabet is an english character from a to z. There should be no special character.
Working of Program :
In the program, we will require a character from user to check and some basic operators to perform the operstion.
Run
#include<stdio.h> int main() { // Write C code here char ch; printf("Enter the character :"); scanf("%c", &ch); if(ch >='a' && ch <= 'z' || ch >='A' && ch <= 'Z'){ printf("Character is Alphabet"); } else{ printf("Character is not an Alphabet"); } return 0; }
Output :
Enter the character : a a Character is Alphabet
In the above program,
- scanf will take the input from the user.
- Condition inside the if block will check whether the character is alphabet or not.
- printf will print the output on the screen
Example :
Let’s solve this problem by typecasting method
Run
#include<stdio.h> int main() { char ch; printf("Enter the character :"); scanf("%c", &ch); if(ch >=32 && ch <=64 || ch >=97 && ch <= 122) { printf("Character is Alphabet"); } else { printf("Character is not an Alphabet"); } return 0; }
Output :
Enter the character : a a Character is Alphabet
What Happened Above?
In the above program, we take character from user but while comparing character with integer in if block typecasting is done to compare the character and integer.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment