In this post, we will discuss the concept of C programming code to check whether the character is Alphabet or not
Here, we are going to learn how to find whether the given character is Alphabet or not
In the C programming language, all the character variables hold an ASCII value for computer usage.ASCII value is represented by integer values between 0 to 127.
The ASCII value of lowercase Alphabets are from 97 to 122 and The ASCII value of uppercase Alphabets are from 65 to 90
This concept is done using three ways
The program allows the user to enter a character thereafter it will check and display the result of the given character whether it is an alphabet or non-alphabet using the if-else statements in C programming language
Program 1
#include <stdio.h> #include <stdlib.h> int main() { char ch; //Asking the user to enter the character printf("enter a caracter as you wish\n"); //Storing the entered character in variable ch scanf("%c",&ch); if((ch>='A' && ch<='Z')||(ch>='a' && ch<='z')){ printf("%c is an Alphabet ",ch); // If the character is an alphabet, it is displayed } else { printf("%c is not an Alphabet ",ch); }// If the character is not an alphabet, it is displayed getch(); return 0; }
When the above code is executed it produces the following result
Case 1
Enter a character as you wish K K is an Alphabet
Case 2
Enter a character as you wish l l is an Alphabet
Case 3
Enter a character as you wish & & is not an Alphabet
Approach
Program 2
The program allows the user to enter a character thereafter it will check and display the result of the given character whether it is an alphabet or non-alphabet using the ternary operator in C programming language
#include <stdio.h> #include <stdlib.h> int main() { char ch; //Ask input the character printf("Enter the character\n"); //Get the input and store the variable ch scanf("%c",&ch); (ch>='A' && ch<='Z')||(ch>='a' && ch<='z') ? printf("It is an Alphabet") : printf("It is not an Alphabet"); getch(); return 0; }
When the above code is executed it produces the following result
Case 1
Enter the character A It is an Alphabet
Case 2
Enter the character c It is an Alphabet
Case 3
Enter the character 5 It is not an Alphabet
Approach
Program 3
The program allows the user to enter a character thereafter it will check and display the result of the given character whether it is an alphabet or non-alphabet using the ASCII value in C programming language
#include <stdio.h> #include <stdlib.h> int main() { char ch; printf("Enter any character\n"); scanf("%c",&ch); if((ch>=97 && ch<=122)||(ch>=65 && ch<=90)){ printf("%c is an Alphabet",ch); } else { printf("%c is not an Alphabet",ch); } getch(); return 0; }
When the above code is executed it produces the following result
Case 1
Enter the character S S is an Alphabet
Case 2
Enter the character c c is an Alphabet
Case 3
Enter the character 5 5 is not an Alphabet
Approach
Suggested for you
If-else statements in C Language
Similar post
C++ code to check whether the character is Alphabet or not
Java code to check whether the character is Alphabet or not
Python code to check whether the character is Alphabet or not
C code to check whether the Alphabet is vowel or consonant
C++ code to check whether the Alphabet is vowel or consonant
Python code to check whether the Alphabet is vowel or consonant
Java code to check whether the Alphabet is vowel or consonant
Java program to print all upper case and lower case Alphabets
C++ program to print all upper case and lower case Alphabets
C program to print all upper case and lower case Alphabets
Java code to print all upper case and lower case Alphabets between the given range
C++ code to print all upper case and lower case Alphabets between the given range
C code to print all upper case and lower case Alphabets between the given range
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…