Codeforcoding

C++ Check whether the given alphabet is upper case or lowercase

C++ Check whether the given alphabet is upper case or lowercase

In this article, we will discuss the concept of the C++ Check whether the given alphabet is upper case or lowercase

In this post, we are going to learn how to check the given alphabet is upper case or lowercase in C++ programming language

C++ Check whether the given alphabet is in upper case or lowercase
Check upper case or lower case

Check whether the given alphabet is upper case or lowercase using Alphabets

The program allows to enter a character, thereafter it checks and displays whether the given character an upper case or lower case or not

Program 1

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    char ch;//Variable declaration
    cout<<"Enter a character: ";
     cin>>ch;//store the entered character
     if(ch>='A' && ch<='Z'){//check upper case
    cout<<ch<<" is an upper case letter ";
}
else if(ch>='A' && ch<='z'){//check lower case
    cout<<ch<<" is a lower case letter ";
}
else{
    cout<<ch<<" is not an Alphabets ";
}
getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter a character: C
C is an upper case letter

 

Case 2

Enter a character: j
j is a lower case letter


Case 3

Enter a character: *
* is not an Alphabets

 

Approach

  1. Define a variable as char ch;
  2. The user is asked to enter a character to check uppercase or lowercase
  3. Use an if statement to check the upper case if the test expression is true,  The tested Alphabet is Uppercase.
  4. When the if-statements is false, The control moves to else if and checks the test expression of else-if
  5. If the test expression of else-if is true, The tested Alphabet is lower case.
  6. If the test expression of else if  is false, control moves to else part and executes else part statement
  7. Finally, the program displays the character whether uppercase or lowercase or not

Check whether the given alphabet is in upper case or lowercase using ASCII

The program allows to enter a character, thereafter it checks and displays whether the given character an upper case or lower case

Program 2

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    char ch;
    cout<<"Enter a character: ";
     cin>>ch;
     if(ch>=65 && ch<=90){
    cout<<ch<<" is an upper case letter ";
}
else if(ch>=97 && ch<=122){
    cout<<ch<<" is a lower case letter ";
}
else{
    cout<<ch<<" is not an Alphabets ";
}
getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter a character: Z
Z is an upper case letter

 

Case 2

Enter a character: k
k is a lower case letter

 

Case 3

Enter a character: 5
5 is not an Alphabets

 

Approach

  1. Define a variable as char ch;
  2. The user is asked to enter a character to check uppercase or lowercase
  3. Use an if statement to check uppercase if the test expression is true,  The tested Alphabet is upper case
  4. When the if-statements is false, The control moves to else if and checks the test expression of else-if
  5. If the test expression of else-if is true,  The tested Alphabet is lower case
  6. If the test expression of else if  is false, control moves to else part and executes else part statement
  7. Finally, the program displays the character whether uppercase or lowercase or not

Suggested for you

Data type in C++ language

Variable in C++ language

The operator in C++ language

If statement in C++ language

 

 

Similar post

Check whether the given alphabet is in upper case or lowercase in Java

Check whether the given alphabet is in upper case or lowercase in Python

Check whether the given alphabet is in upper case or lowercase in C

Python Check whether the given alphabet is upper case or lowercase
C Check whether the given alphabet is upper case or lowercase
Exit mobile version