Case conversion algorithm training
Time limit: 1.0s Memory Limit: 512.0MB
Description of the problem
to write a program, enter a string (a length of no more than 20), then each character in the string case conversion, is about to become a lowercase uppercase letters, lowercase letters capitalized, then the new string output.
Input formats: Enter a string, and the string contains only letters which does not include other types of characters, and no spaces.
Output format: outputs the converted string.
Sample input and output
Sample input
AeDb
Sample Output
aEdB
#include <stdio.h>
#include <string.h>
int main()
{
char s[25] = { 0 };
scanf("%s", s);
for (int i = 0; i < strlen(s); ++i)
{
if ('A' <= s[i] && s[i] <= 'Z')
s[i] = 'a' + s[i] - 'A';
else
s[i] = 'A' + s[i] - 'a';
}
printf("%s", s);
return 0;
}