Problem Statement

You’re given a string. You need to convert all the characters of this string to the opposite cases.

Example 1: Let str = “Welcome to MUO”

String after converting all the characters to the opposite cases = “wELCOME TO muo”

Thus, the output is “wELCOME TO muo”.

Example 2: Let str = “Fuzzy Wuzzy was a bear. Fuzzy Wuzzy had no hair.”

String after converting all the characters to the opposite cases = “fUZZY wUZZY WAS A BEAR. fUZZY wUZZY HAD NO HAIR.”

Thus, the output is “fUZZY wUZZY WAS A BEAR. fUZZY wUZZY HAD NO HAIR.”.

Example 3: Let str = “Tom threw Tim three thumbtacks”

String after converting all the characters to the opposite cases = “tOM THREW tIM THREE THUMBTACKS”

Thus, the output is “tOM THREW tIM THREE THUMBTACKS”.

C++ Program to Convert Characters of a String to the Opposite Cases

Below is the C++ program to convert the characters of a string to the opposite cases:

Output:

Python Program to Convert Characters of a String to the Opposite Cases

Below is the Python program to convert the characters of a string to the opposite cases:

Output:

JavaScript Program to Convert Characters of a String to the Opposite Cases

Below is the JavaScript program to convert the characters of a string to the opposite cases:

Output:

C Program to Convert Characters of a String to the Opposite Cases

Below is the C program to convert the characters of a string to the opposite cases:

Output:

Learn More About String Manipulation

In this article, you learned how to convert characters of the string to opposite cases. Dealing with strings and texts is an integral part of programming. You must know how to manipulate strings.

Python is a solid choice to get started with if you’re looking for a language to manipulate strings easily and efficiently.