codescracker


c++

C++ Program to Convert Uppercase to Lowercase



« Previous Program Next Program »


Uppercase to Lowercase Conversion in C++

To convert a character from uppercase to lowercase in C++ programming, you have to ask to the user to enter a character in uppercase to convert it into lowercase and display the equivalent character in lowercase. To change uppercase character into lowercase character, just add 32 in character in uppercase to convert it into lowercase. Since ASCII value of A is 65 and ASCII value of a is 97. So, 65+32 = 97 = a = equivalent value of A in lowercase i.e., a.

C++ Programming Code to Convert Uppercase Character to Lowercase

The following C++ program ask to the user to enter a character in uppercase to convert it into lowercase, then display the result on the screen. Since ASCII value of A is 65 and ASCII value of a is 97. So to convert a character from uppercase to lowercase, we have to add (97-65) i.e., 32 to get the ASCII value of the character in lowercase. Then print it on the screen :

/* C++ Program - Convert Uppercase Character to Lowercase */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	char ch;
	cout<<"Enter a character in uppercase : ";
	cin>>ch;
	ch=ch+32;
	cout<<"character in lowercase = "<<ch;
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program convert uppercase lowercase

C++ Programming Code to Convert Uppercase String to Lowercase

Now let's convert string from uppercase to lowercase. So, the following C++ program ask to the user to enter a string like first name in uppercase to change it into lowercase, then display the result on the screen:

/* C++ Program - Convert Uppercase String to Lowercase */
		
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
  clrscr();
  char str[20];
  int i;
  cout<<"Enter the String (Enter First Name) in uppercase : ";
  gets(str);
  for(i=0;i<=strlen(str);i++)
  {
	    if(str[i]>=65 && str[i]<=92)
	    {
		str[i]=str[i]+32;
	    }
  }
  cout<<"\nThe String in Lowercase = "<<str;
  getch();
}

When the above C++ program is compile and executed, it will produce the following result:

uppercase to lowercase conversion in c++ programming

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test