编写函数int yuanyin(char s[20]),功能是统计并返回字符串中元音字母(A,E,I,O,U)的总个数(包含大小写)。
时间: 2024-05-01 19:22:20 浏览: 22
下面是一个简单的实现方式:
```c
int yuanyin(char s[20]) {
int count = 0;
for (int i = 0; s[i] != '\0'; i++) {
switch (s[i]) {
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
count++;
break;
default:
break;
}
}
return count;
}
```
该函数遍历字符串中的每个字符,如果是元音字母,则计数器加一。使用 switch 语句可以使代码更加简洁易读。注意要将字符串末尾的空字符 '\0' 作为循环结束的条件。
相关问题
输入一个以换行结束的字符串,统计并输出字符串中元音字母的个数(元音字母:'A','E','I','O','U' ,'a','e','i','o','u')
以下是统计字符串中元音字母个数的Python代码示例:
```python
yuanyin_list = ('A','E','I','O','U','a','e','i','o','u')
print('请输入字符串:')
s = input()
sum = 0
for i in s:
if i in yuanyin_list:
sum = sum + 1
print('元音字母出现了 {} 次'.format(sum))
```
这段代码首先定义了一个包含所有元音字母的列表`yuanyin_list`,然后通过`input()`函数获取用户输入的字符串。接下来,使用一个循环遍历字符串中的每个字符,如果字符在`yuanyin_list`中,则将计数器`sum`加1。最后,使用`format()`函数将结果输出。
home/lwt/.bash_profile" "/home/lwt/.bash_profile" E212: Can't open file for writing Press ENTER or type command to continue 什么yuanyin
这个错误通常是由于权限问题导致的。可能是你没有足够的权限来写入该文件,或者该文件被其他进程占用,导致无法写入。
你可以尝试使用sudo命令来以管理员身份运行编辑器,例如:
```
sudo vi /home/lwt/.bash_profile
```
然后输入管理员密码进入编辑器,对文件进行编辑并保存。如果还是无法写入,可能需要检查该文件的权限设置和所有者信息。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)