用c语言怎么实现 输入一个以回车符结束的字符串(不超过80个字符),统计其中元音字母的个数。

如题所述

1 通过gets读入字符串,这个函数是专门读一行的。

2 遍历字符串,判断是否为元音,也就是a,e,i,o,u,注意大小写。

3 如果是,累加。

4 遍历结束后,输出结果。

代码如下:

int main()
{
    char s[90];
    int i,c=0;
    gets(s);
    for(i = 0; s[i]; i ++)
    {
        if(s[i]>='A'&&a[i]<='Z') s[i]+=32;//大写转小写,方便判断。
        if(s[i] == 'a'||s[i] == 'e'||s[i] == 'i'||s[i] == 'o'||s[i] == 'u')
          c++;
    }
    printf("%d",c);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-01-04

具体实现方法和结果展示如下:

第2个回答  2010-12-17
#include <stdio.h>
#include <string.h>
#define max 100
//A、E、I、O、U
void main(){
char ch[max],*p;
int n,i;
printf("******************求字符串中元音字母的个数*******************\n");
printf("请输入一个字符串(个数 n<80 ):\n");gets(ch);
p=ch; n=0;
while(*p){
if (*p=='A'||*p=='E'||*p=='I'||*p=='O'||*p=='U'||*p=='a'||*p=='e'||*p=='i'||*p=='o'||*p=='u')
{
n++;
}
p++;
}
printf("元音字母的个数为:\n%d\n",n);
}本回答被网友采纳
第3个回答  2010-12-17
#include<stdio.h>
#include<string.h>
void main()
{
char a[80],b;
int i,t,g,j=0;
printf("请输入一个字符串(少于80个字符)\n");
gets(a);
t=strlen(a);
printf("%d\n",t);
printf("再输入一个字符,即可统计此字符在字符串的个数\n");
b=getchar();

for(i=0;i<t;i++)
{
if(a[i]==b)

j++;
}
printf("字符%c出现个数为=%d\n",b,j);
}

参考资料:mail

第4个回答  2010-12-18
#include <stdio.h>
#include <string.h>

void main()
{
int i, len;
char temp;
char buf[512] = ;

scanf("%s", buf);
len = strlen(buf);

for (i = 0; i < len/2; i++)
{
temp = buf[i];
buf[i] = buf[len - 1 - i];
buf[len - 1 - i] = temp;
}

printf("%s", buf);
}
相似回答