小写字母变大写的c语言代码
以下是将小写字母转换为大写字母的 C 语言代码:
#include <stdio.h> #include <ctype.h>
int main() { char c; printf("请输入一个小写字母:\n"); scanf("%c", &c); if(islower(c)) { c = toupper(c); printf("转换后的大写字母为:%c\n", c); } else { printf("输入的不是小写字母!\n"); } return 0; }
c语言小写字母变大写大写变小写
我们可以使用C语言内置的函数来实现小写字母变大写,大写变小写的操作。具体实现代码如下:
#include <stdio.h>
#include <ctype.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
if (islower(ch)) {
printf("Uppercase character: %c", toupper(ch));
} else if (isupper(ch)) {
printf("Lowercase character: %c", tolower(ch));
} else {
printf("Invalid input!");
}
return 0;
}
在上面的代码中,我们首先使用 scanf
函数获取用户输入的字符,然后使用 islower
函数判断输入的字符是否为小写字母,如果是,则使用 toupper
函数将其转换为大写字母并输出;如果不是,则使用 isupper
函数判断输入的字符是否为大写字母,如果是,则使用 tolower
函数将其转换为小写字母并输出;如果既不是小写字母也不是大写字母,则输出提示信息。
请输入一个大写字母,然后转成小写字母输出的c语言代码
#include <stdio.h>
int main() { char c; printf("请输入一个大写字母:"); scanf("%c", &c); if (c >= 'A' && c <= 'Z') { c += 32; printf("转换后的小写字母为:%c\n", c); } else { printf("输入的不是大写字母!\n"); } return 0; }
相关推荐















