Write a program to input a string in mixed case and display all the uppercase charaters in lowercase and vice versa
Answers
Take one string of any length and calculate its length.
Scan string character by character and keep checking the index .
If character in a index is in lower case, then subtract 32 to convert it in upper case, else add 32 to convert it in upper case
Print the final string.
// CPP program to Convert characters
// of a string to opposite case
#include<iostream>
using namespace std;
// Function to convert characters
// of a string to opposite case
void convertOpposite(string &str)
{
int ln = str.length();
// Conversion according to ASCII values
for (int i=0; i<ln; i++)
{
if (str[i]>='a' && str[i]<='z')
//Convert lowercase to uppercase
str[i] = str[i] - 32;
else if(str[i]>='A' && str[i]<='Z')
//Convert uppercase to lowercase
str[i] = str[i] + 32;
}
}
// Driver function
int main()
{
string str = "GeEkSfOrGeEkS";
// Calling the Function
convertOpposite(str);
cout << str;
return 0;
}
[i hope ti helps you]