31/10/2015

C++ Program To Convert A Lower Case To Upper Case Or Vice-Versa

Problem :- Write A Program To Convert A Lower Case To Upper Case Or Vice-Versa

Logic :- Convert Lower to upper and upper to lower .we use ASCII value as we know that 'a' to 'z' ASCII is '97' to '122' And 'A' to 'Z' ASCII is '65' to '90' .
so if want to convert lower to upper then minus 32 to character 
and if you want to convert upper to lower then add 32 to character .

Solution :-

#include<iostream>
using namespace std;
int main()
{
  //By-Ghanendra Yadav
  char ch;
  cout<<"Enter any Alphabet :\n";
  cin>>ch;

if(ch>='a'&&ch<='z')
{
  cout<<"\nYou Entered A Lowercase Alphabet\n";
  ch=ch-32;
  cout<<"\nThe uppercase alphabet is "<<ch;
}
else
{
  cout<<"\nYou Entered An Uppercase Alphabet\n";
  ch=ch+32;
  cout<<"\nTe Lowercase Alphabet Is "<<ch;
}
cout<<endl;
return 0;

}

Output:-

C++ Program To Convert A LowerCase To UpperCase Or Vice-Versa

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: