codinasion-archive / codinasion-monorepo

Community Monorepo
https://codinasion.org
MIT License
52 stars 170 forks source link

[Program]: Convert string to reversecase #3820

Closed harshraj8843 closed 3 months ago

harshraj8843 commented 1 year ago

Description

Write a program to convert string to reversecase

Reversecase is a style of writing in which all lowercase letters are converted to uppercase and all uppercase letters are converted to lowercase.

Input  : "hello world"
Output : "HELLO WORLD"

Tracking Issues

Sankalps-world commented 5 months ago

include

include

std::string reverseCase(const std::string& str) { std::string result = str; for (char& c : result) { if (std::islower(c)) { c = std::toupper(c); } else if (std::isupper(c)) { c = std::tolower(c); } } return result; }

int main() { std::string inputString; std::cout << "Enter a string: "; std::getline(std::cin, inputString);

std::string reversedCaseString = reverseCase(inputString);

std::cout << "String in reverse case: " << reversedCaseString << std::endl;

return 0;

}