C语言编译一个程序,输入一串字符,大写字母不输出,输出其它字符
时间: 2024-05-12 10:20:55 浏览: 16
下面是一个简单的C语言程序,实现输入一串字符,大写字母不输出,输出其它字符:
```c
#include <stdio.h>
int main() {
char c;
printf("请输入一串字符:\n");
while ((c = getchar()) != '\n') {
if (c >= 'A' && c <= 'Z') {
continue; // 大写字母不输出,跳过本次循环
}
putchar(c); // 输出其它字符
}
printf("\n");
return 0;
}
```
程序中使用了 `getchar()` 函数来逐个读取输入的字符,使用 `putchar()` 函数输出字符。使用 `continue` 关键字来跳过大写字母,在循环中继续读取下一个字符。最后输出一个换行符来美化输出结果。
相关问题
c语言程序:输入一串字符(以回车键结束),统计其中数字、大写字母、小写字母以及其他字符的个数。
下面是一个示例的C语言程序,可以实现你的要求:
```c
#include <stdio.h>
int main() {
char input;
int digits = 0, uppercase = 0, lowercase = 0, others = 0;
printf("请输入一串字符(以回车键结束):\n");
while ((input = getchar()) != '\n') {
if (input >= '0' && input <= '9') {
digits++;
} else if (input >= 'A' && input <= 'Z') {
uppercase++;
} else if (input >= 'a' && input <= 'z') {
lowercase++;
} else {
others++;
}
}
printf("数字个数:%d\n", digits);
printf("大写字母个数:%d\n", uppercase);
printf("小写字母个数:%d\n", lowercase);
printf("其他字符个数:%d\n", others);
return 0;
}
```
你可以将以上代码保存为一个`.c`文件,然后使用C语言编译器进行编译和运行。运行程序后,输入你想要统计的字符串,程序将会输出数字、大写字母、小写字母以及其他字符的个数。
c语言从键盘输入一个字符串并保存起来,统计该字符串中大写字母、小写字母、数字、其他字符的个数
好的,以下是 C 语言实现该功能的代码:
```c
#include <stdio.h>
#include <ctype.h>
int main() {
char str[100];
int upper = 0, lower = 0, digit = 0, other = 0;
// 读取字符串
printf("请输入一个字符串:\n");
scanf("%s", str);
// 统计字符个数
for (int i = 0; str[i] != '\0'; i++) {
if (isupper(str[i])) {
upper++;
} else if (islower(str[i])) {
lower++;
} else if (isdigit(str[i])) {
digit++;
} else {
other++;
}
}
// 输出结果
printf("大写字母个数:%d\n", upper);
printf("小写字母个数:%d\n", lower);
printf("数字个数:%d\n", digit);
printf("其他字符个数:%d\n", other);
return 0;
}
```
你可以将上述代码复制到 C 语言开发环境中进行编译和运行。然后按照提示输入一个字符串,即可得到大写字母、小写字母、数字、其他字符的个数的统计结果。