Computer Science, asked by Rajinderkhurana352, 9 months ago

write a program to input a string and change the case of the string and print the new string

Answers

Answered by barkhajaiswal99073
0

Explanation:

jejejhehdhvbnnsmzmsknzjzjzjzjzjdjdjsjdjdjddkid

Answered by pranjali2007
3
Given a string, convert the characters of the string into opposite case,i.e. if a character is lower case than convert it into upper case and vice-versa.
Examples:

Input : geeksForgEeks
Output : GEEKSfORGeEKS

Input : hello every one
Output : HELLO EVERY ONE
Recommended: Please try your approach on {IDE} first, before moving on to the solution.

ASCII values of alphabets: A – Z = 65 to 90, a – z = 97 to 122
Steps:

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 lower case
Print the final string.
C++JavaPython3C#
filter_none
edit
play_arrow
brightness_4
// CPP program to Convert characters
// of a string to opposite case
#include
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 {
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;
}

Output:
gEeKsFoRgEeKs
Time Complexity: O(n)

Note: This program can alternatively be done using C++ inbuilt functions – Character.toLowerCase(char) and Character.toUpperCase(char).

Plz mark my answer as brainiest

Follow me

Hope this helps u
Similar questions