codescracker


c++

C++ Program to Convert Lowercase to Uppercase



« Previous Program Next Program »


Lowercase to Uppercase Conversion in C++

To convert the uppercase string into lowercase string in C++ programming, you have to ask to the user to enter the string, now start converting lowercase string to uppercase string by using ASCII values. To convert lowercase to uppercase, just minus 32 from the all string's character since the ASCII value of A is 65 and the ASCII value of a is 97. That is, 97-65=32. So to convert string from lowercase to uppercase just minus 32 from each character of the string as shown here in the following program.

C++ Programming Code to Convert Lowercase to Uppercase

Following C++ program ask to the user to enter any string like first name in lowercase to convert it into uppercase, then display the result on the screen:

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

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

C++ program convert string lowercase to uppercase

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