
AI
c#include #include int mAIn() { char str[100]; printf("请输入一个字符串:"); scanf("%s", str); int len = strlen(str); char* new_str = (char*)malloc(sizeof(char) * len); int i; for (i = 0; i < len; i++) { if (isupper(str[i])) { new_str[i] = toupper((unsigned char)str[i]); } else if (islower(str[i])) { new_str[i] = tolower((unsigned char)str[i]); } else { new_str[i] = str[i]; } } printf("%s", new_str); printf("程序已执行完毕。"); return 0;}
以上程序中,首先通过scanf函数读取一个字符串,并使用指针new_str保存大小写不同的新字符串。然后遍历原字符串中的每个字符,如果为大写字母,则使用toupper函数转换为小写字母;如果为小写字母,则使用tolower函数转换为大写字母。最后,将转换后的字符复制到新的字符串中,并输出结果。此程序适用于C语言编译器和执行环境。如果需要其他语言的实现方式,请提供更多信息以便我给出正确的回答。Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号