网易 购物:C语言编程

来源:百度文库 编辑:神马品牌网 时间:2024/04/27 17:19:04
编写一个程序,计算一行文字中的元音和辅音的个数,元音(a,e,i,o,u)
只能用循环和数组!谢谢各位大哥

参考3楼的程序和4楼的意见修改一下:
#include <stdio.h>
main()
{
int count1=0,count2=0;
char words[100] = {0};
gets(words);
for (int j=0; j<strlen(words); j++) {
if(words[j]>='A'&&words[j]<='Z' || words[j]>='a'&&words[j]<='z') {
switch(words[j]) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':count++;break;
default :count2++;
}
}
}
printf("元音个数为:%d\n辅音个数为:%d\n",count1,count2);
}

我的天哪。这样的问题也也来问啊。构造一个五个成员的一维a[0]a[1]a[2]a[3]a[4]分别存储五个元音的个数。一个循环直到字符串结束为止。利用IF或者是CASE判断就可以了

楼上有点不合题意啊 我来改改

#include <stdio.h>
main()
{
int count1=0,count2=0;
char words[100] = {0};
gets(words);
for (int j=0; j<strlen(words); j++) {
switch(words[j]) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':count++;break;
default :count2++;
}
}
printf("元音个数为:%d\n辅音个数为:%d\n",count1,count2);
}

楼上没有判断大小写,没有判断不是字母的情况