Write a program to check whether a character is alphabet or not

A character is said to be an alphabet if it is from A-Z or a-z.
We will see this program using two ways, i.e., using the character and using the ASCII(American Standard Code foo Information Interchange).
A-Z ----- 65-90
a-z  -----  97-122

By directly checking the inputted character:-

  #include<stdio.h>
    void main()
     {
        char ch;
        printf("Enter a character:");
        scanf("%c", &ch);

        if( (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') ) 
        printf("Character is an alphabet.");

        else
        printf("Character is not an alphabet."); 
      }

By using ASCII value of the character:-

  #include<stdio.h>
    void main()
      {
         char ch;
         printf("Enter a character:");
         scanf("%c", &ch);
          
        if( (ch >= 65 && ch <=90) || (ch >=97 && ch <= 122) )
        printf("Character is an alphabet.");

        else
        printf("Character is not an alphabet."); 
      }









Post a Comment

0 Comments