PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Program Based on If & Else

Program to check whether a character is uppercase or lowercase

Input - Output

Input
Enter a character : E

Output
E is an uppercase alphabet

Input
Enter a character : r

Output
r is a lowecase alphabet

Algorithm

Step 1: START

Step 2: Enter an alphabet 'ch' as an input.

Step 3: Check the condition:

    if(ch>='A' && ch<='Z' || ch>='a' && ch<='z')

      if(ch>='A'&& ch<='Z')

        print the character is in uppercase

     else

        print the character is in lowercase

   else

       print It is not an alphabet

Step 4: END

CODE


/* Check an alphabet is in lowecase or uppercase */
#include  <stdio.h>
int main()
{
      char ch;
      printf(" Enter an alphabet : ");
      scanf("%c",&ch);
      if(ch>='A' && ch<='Z' || ch>='a' && ch<='z')
          if(ch>='A'&& ch<='Z')
              printf(" %c is an uppercase alphabet",ch);
          else
              printf(" %c is a lowercase alphabet",ch);
      else
          printf(" %c is not an alphabet ",ch);
    return 0;
}


/* Check an alphabet is in lowecase or uppercase */
#include <iostream>
using namespace std;
int main()
{
      char ch;
      cout<<" Enter a character: ";
      cin>>ch;
      if(ch>='A' && ch<='Z' || ch>='a' && ch<='z')
          if(ch>='A' && ch<='Z')
              cout<<ch<<" is an uppercase alphabet";
          else
              cout<<ch<<" is a lowercase alphabet";
      else
          cout<<ch<<" is not an alphabet";
    return 0;
}

OutPut

Enter a character : E

E is an uppercase alphabet