C++ Program to Convert String lowercase to UPPERCASE

Question : Write a C++ Program to Convert String lowercase to UPPERCASE?

Explain: C++ language Question about conversion String lowercase to UPPERCASE with input from user.

Formula:
65 to 90 ASCII code for Upper characters 
97 to 122 ASCII code for Upper characters 
so for conversion lower case to upper case -32  
for example a ASCII code is 141 for convert UPPERCASE subtract 32 now 65 is equal to UPPERCASE A

Solution:

 /************************************************************ 
     C++ Program for Convert String lowercase to UPPERCASE
 *************************************************************
***************** By www.cpplanguage.com *********************/

#include<iostream>
#include<string>
using namespace std;
int main()
{
  int c,length;
  char string[20];
  cout<<"Enter You String Value: ";
// getting input
  cin>>string;
// find length of string with strlen function
  length=strlen(string);
  for(c=0;c<=length;c++)
  {
// if lowercase range between 97 & 122 then - 32 for Uppercase Range and store in String
    if(string[c]>=97 && string[c]<=122)
    {
string[c]=string[c]-32;
    }
  }
  cout<<"String in Uppercase = "<<string<<endl;
  return 0;
}

Output:
 C++ Language Program for Convert String lowercase to UPPERCASE

No comments:

Post a Comment