Program:
#include <iostream>
using namespace std;
string lowerToUpper(string s)
{
string ans;
for(int i = 0; i < s.length(); i++)
{
//if a character of string is in lower case
if(s[i] >= 'a' && s[i] <= 'z')
ans += s[i]-32;
//if a character is uppercase, digit, space or underscore
else
ans += s[i];
}
return ans;
}
int main()
{
string s = "hello world";
cout << lowerToUpper(s);
return 0;
}
Output:
HELLO WORLD
If you want to convert uppercase to lowercase then instead of addition, subtract s[i] with 32._____________________________________________________________________________________________
C++ Program To Convert Lowercase into Upper case
Reviewed by Beast Coder
on
March 20, 2021
Rating:
No comments: