马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
int main()
{
char ch;
int count = 0;
int a = 0, e = 0, i = 0, o = 0, u = 0;
printf("Please input your sentence:");
while((ch = getchar()) != '\n')
{
if(ch = 'a')
{
a++;
count++;
}
else if(ch = 'e')
{
e++;
count++;
}
else if(ch = 'i')
{
i++;
count++;
}
else if(ch = 'o')
{
o++;
count++;
}
else if(ch = 'u')
{
u++;
count++;
}
else
continue;
}
printf("There are %d vowels in this sentence\n", count);
printf("a(%d),e(%d),i(%d),o(%d),u(%d)\n",a,e,i,o,u);
return 0;
}
程序里面没用答案的switch。。。 目标是统计小写元音字母,但是统计结果是所有输入的字符,请大神帮忙看看是什么问题。。
你好 在if() 里面的比较中 用== 而不是=
#include <stdio.h>
int main()
{
char ch;
int count = 0;
int a = 0, e = 0, i = 0, o = 0, u = 0;
printf("Please input your sentence:");
while((ch = getchar()) != '\n')
{
if(ch == 'a')
{
a++;
count++;
}
else if(ch == 'e')
{
e++;
count++;
}
else if(ch == 'i')
{
i++;
count++;
}
else if(ch == 'o')
{
o++;
count++;
}
else if(ch == 'u')
{
u++;
count++;
}
else
continue;
}
printf("There are %d vowels in this sentence\n", count);
printf("a(%d),e(%d),i(%d),o(%d),u(%d)\n",a,e,i,o,u);
return 0;
}
|