Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Thursday, October 1, 2020

C Program to check character is alphabet or digit

C program to check whether given character is alphabet or digit

Write a C program to input a character from user and check whether a given character is alphabet or digit using if...else...if statement. Have a look at the below step by step logic to check whether a given character is alphabet or digit.

Example:

  1. INPUT

  2. Enter a character: L

  OUTPUT

L is a alphabet character.

Required knowledge for this exercise

Logic to check whether a given character is alphabet or digit:

In C programming, every character has an unique ASCII value (An integer value between 0 to 127 is known as ASCII value).Which is used to represent a character in memory. In memory every character is stored as an integer. 

C Program To Check For Alphabet, Number and Special Symbol
 
Now let's see the below step by step logic to check given character is alphabet or digit.

1) Input a character from user and store it in variable ch using scanf() fucntion.
2) Check the below conditions:
  1.  if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) then, it is an   ALPHABET.
  2.  if ((ch >= '0' && ch <= '9') then, it is a DIGIT.
 Otherwise neither ALPHABET nor DIGIT


Program to check whether a character is alphabet or digit using if...else...if: 

  1. /* C program to check whether a character is alphabet or digit */ #include <stdio.h> int main() { char ch; /* Input a character from user */ printf("Please Enter any character: "); scanf("%c", &ch); if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { printf("\n%c is an Alphabet.", ch); } else if ((ch >= '0' && ch <= '9') { printf("\n%c is a digit.", ch); }
  2. else { printf("\n%c neither Alphabet nor digit.", ch); } return 0; }

You can also use the ASCII value to check alphabets character. Since we know that, every character has an unique ASCII value (An integer value between 0 to 127). For example: ASCII value of a=97, z=122, A=65, Z=90 and 0=48, 9=57.

Have a look at the below program to check whether a character is alphabet or not using ASCII Value: 

  1. /* C program to check whether a character is alphabet, digit or not */ #include <stdio.h> int main() { char ch; /* Input a character from user */ printf("Please Enter any character: "); scanf("%c", &ch); if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90)) { printf("\n%c is an Alphabet.", ch); } else if ((ch >= 48 && ch <= 57) { printf("\n%c is a digit." ch); }
  2. else { printf("\n%c neither Alphabet nor digit.", ch); } return 0; }

Output:
  1. Please Enter any character: L
  2.  L is an alphabet.

  1. Please Enter any character: 10
  2. 10 is  a digit.





Next topic >> to be updated soon.

Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us