Alphabets

C++ program: Check whether the given character is upper or lower case or not

C++ program: Check whether the given character is upper or lower case or not

In this article, we will discuss the concept of C++ program: Check whether the given character is upper or lower case or not

In this post, we are going to learn how to write a program to  check whether given character is Upper case or lower case or not using if else in C++ language

Code to find given character is Upper or Lower or not

Code to find given character Upper or Lower or not, using if statements

In this code, we are going to learn how to check  the given  character is Upper case or lower case or not using if else statements in C++ language

Program 1

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

using namespace std;

int main()
{
    char ch;//declare character variable
    cout<<"Enter a character: ";
    //Ask input from the user
     cin>>ch;//reading the input
     if(ch>='A' && ch<='Z'){//check upper case letter
  cout<<ch<<" is an upper case letter ";
}
else if(ch>='a' && ch<='z'){//check lower case letter
  cout<<ch<<" is a lower case letter ";
}
else{//Display if it is not in Alphabets
  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: n
n is a lower case letter

Case 2

Enter a character: C
C is an upper case letter

Case 3

Enter a character: *
* is not an Alphabet

 

Code to find given character Upper or Lower or not, using Ascii

In this code, we are going to learn how to check  the given  character is Upper case or lower case or not using Ascii value in C++ language

Program 2

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

using namespace std;

int main()
{
    char ch;//declare character variable
    cout<<"Enter a character: ";
    //Ask input from the user
     cin>>ch;//reading the input
     if(ch>=65 && ch<=90){//check upper case letter
  cout<<ch<<" is an upper case letter ";
}
else if(ch>=97 && ch<=122){//check lower case letter
  cout<<ch<<" is a lower case letter ";
}
else{//Display if it is not in Alphabets
  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: A
A is an upper case letter

Case 2

Enter a character: n
n is an lower case letter

Case 3

Enter a character: *
* is not an Alphabet

 

Suggested post

If else statement in C++

Nested if statement in C++

Operator in C++ language

Switch statements in C++ language

 

Similar post

Java program to print all alphabets in given range

C program to print all alphabets in given range

C++ program to print all alphabets in given range

 

Java program to print all alphabets using loops

C program to print all alphabets using loops

C++ program to print all alphabets using loops

 

Java program to check whether a character is Alphabet or Not

C++ program to check whether a character is Alphabet or Not

C program to check whether a character is Alphabet or Not

Python program to check whether a character is Alphabet or Not

 

Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.