Header Ads Widget

C++ program to check whether a character is uppercase or lowercase alphabet

 

 C++ program to check whether a character is uppercase or lowercase alphabet

Given a character , write a program to check whether it is uppercase or lowercase .

Method 1: By using standard function ( isupper() and islower() ) .

Method 2: By Checking range i.e ( if Character is in range A to Z then uppercase ).

Method 3: By using Ascii values . (Ascii of A to Z is 65 to 90 and Ascii value of a to z is 97 to 122 )

Sample input

A 

Sample output

A is Uppercase

C++ program to check whether a character is uppercase or lowercase alphabet

The objective of the code is to check whether it is uppercase or lowercase alphabet .

Method 1:

#include <bits/stdc++.h>
using namespace std;

int main()
{
   char ch;
cin>>ch;
if(isupper(ch))
cout<<ch<<" is Uppercase";
else if(islower(ch))
cout<<ch<<" is Lowercase";
else
cout<<"Invalid input";
return 0;
}


Output:-

A
A is Uppercase

Method 2:

#include <bits/stdc++.h>
using namespace std;

int main()
{
   char ch;
cin>>ch;
if(ch>='A' && ch<='Z')
cout<<ch<<" is Uppercase";
else if(ch>='a' && ch<='z')
cout<<ch<<" is Lowercase";
else
cout<<"Invalid input";
return 0;
}

Output:-

A
A is Uppercase

Method 3 : (By using Ascii value)

#include <bits/stdc++.h>
using namespace std;

int main()
{
   char ch;
int a;
cin>>ch;
// converting character into
// integer i.e Ascii value
a=ch;
if(a>=65 && a<=90)
cout<<ch<<" is Uppercase";
else if(a>=97 && a<=122)
cout<<ch<<" is Lowercase";
else
cout<<"Invalid input";
return 0;
}


Output:-

A
A is Uppercase

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-