用DEVc++写:输入一行英文单词序列,单词是指连续不含空格的字符串,各单词之间用空格分开,空格数可以是多个。 1.对应地计算每个单词的长度; 2.将每个单词的首字母改为大写后输出; 3.统计其中单词的个数。
时间: 2024-06-06 07:09:27 浏览: 18
ChitGPT: 你好,很高兴为您服务。以下是您提出的问题的答案:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
char str[100];
int len, cnt = 0;
printf("请输入英文单词序列:\n");
fgets(str, 100, stdin); // 读入字符串
len = strlen(str);
// 对应地计算每个单词的长度
printf("每个单词的长度为:\n");
for (int i = 0; i < len; i++) {
if (str[i] == ' ') {
printf("\n");
} else {
printf("%c", str[i]);
}
}
// 将每个单词的首字母改为大写后输出
printf("\n\n将每个单词的首字母改为大写后输出:\n");
for (int i = 0; i < len; i++) {
if (i == 0 || str[i-1] == ' ') {
printf("%c", toupper(str[i]));
} else {
printf("%c", str[i]);
}
}
// 统计其中单词的个数
printf("\n\n单词的个数为:\n");
for (int i = 0; i < len; i++) {
if (str[i] == ' ') {
cnt++;
}
}
printf("%d", cnt+1);
return 0;
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)