C语言数组输入一行字符,分别统计其中每个元音字母(aeiou不分大小写)的个数?
程序运行示例如下:inputalineofcharacter:Houoldareyou?11031...
程序运行示例如下:
input a line of character:
Hou old are you?
1 1 0 3 1 展开
input a line of character:
Hou old are you?
1 1 0 3 1 展开
2个回答
展开全部
已经调试过,麻烦给分
#include "stdio.h"
using namespace std;
char tolower(char c)
{
if (c >= 'A'&& c <= 'Z')
{
c = c + 32;
}
return c;
}int main()
{
int a, b, c, d, e;
a = b = c = d = e = 0;
char strs[1024];
printf("%s","input a line of character:\r\n");
scanf("%s", strs);
for each (char c in strs)
{
if (tolower(c) == 'a')
{
a++;
}
else if (tolower(c) == 'e')
{
b++;
}
else if (tolower(c) == 'i')
{
c++;
}
else if (tolower(c) == 'o')
{
d++;
}
else if (tolower(c) == 'u')
{
e++;
}
}
printf("%d%d%d%d%d", a, b, c, d, e);
return 0;
}
TableDI
2024-07-18 广告
2024-07-18 广告
在Excel中匹配两列数据,通常有以下几种方法:1. **使用VLOOKUP函数**:该函数可根据指定值,在另一列或区域中查找并返回对应的结果。例如,在C1单元格输入`=VLOOKUP(A1,B:B,1,FALSE)`,即可查找A1在B列中...
点击进入详情页
本回答由TableDI提供
展开全部
#include<stdio.h>
#define MAX 5
int main() {
char s[100];
int count[MAX]={0},i,j;
char c[MAX]="aeiou";
printf("input a line of character:\n");
gets(s);/*输入*/
for(i=0;s[i]!='\0';i++)
{
if(s[i]>='A' && s[i]<='Z') s[i]+=32;/*如果为大写则转为小写*/
for(j=0;j<MAX;j++) /*判断是否出现过元音字母*/
{
if(s[i]==c[j]) /*如果出现则数组计数加1,跳出当前循环*/
{
count[j]++;
break;
}
}
}
for(i=0;i<MAX;i++) printf("%d ",count[i]);/*输出结果*/
return 0;
}
#define MAX 5
int main() {
char s[100];
int count[MAX]={0},i,j;
char c[MAX]="aeiou";
printf("input a line of character:\n");
gets(s);/*输入*/
for(i=0;s[i]!='\0';i++)
{
if(s[i]>='A' && s[i]<='Z') s[i]+=32;/*如果为大写则转为小写*/
for(j=0;j<MAX;j++) /*判断是否出现过元音字母*/
{
if(s[i]==c[j]) /*如果出现则数组计数加1,跳出当前循环*/
{
count[j]++;
break;
}
}
}
for(i=0;i<MAX;i++) printf("%d ",count[i]);/*输出结果*/
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询