求c语言 指点!!!从键盘输入一串英文字母,统计每个字母的个数,并输出字母及相应的个数
答案:3 悬赏:0
解决时间 2021-03-07 04:18
- 提问者网友:很好的背叛
- 2021-03-06 04:48
疑问:又不知道执行者会输入几种字母,如果输入26个字母,那我不是要定义26个变量统计各个字母出现的个数
最佳答案
- 二级知识专家网友:不傲怎称霸
- 2021-03-06 05:48
#include
#include
int main(int argc,char *argv[])
{
char c;
static int digit,alpha,other,space;
while ((c=getchar())!='\n')
if (isdigit(c)) digit++;
else if (isalpha(c)) alpha++;
else if (isspace(c)) s缉肠光段叱灯癸犬含华pace++;
else other++;
printf("alpha:%d\ndigit:%d\nspace:%d\nother:%d\n",alpha,digit,space,other);
return 0;
}
#include
int main(int argc,char *argv[])
{
char c;
static int digit,alpha,other,space;
while ((c=getchar())!='\n')
if (isdigit(c)) digit++;
else if (isalpha(c)) alpha++;
else if (isspace(c)) s缉肠光段叱灯癸犬含华pace++;
else other++;
printf("alpha:%d\ndigit:%d\nspace:%d\nother:%d\n",alpha,digit,space,other);
return 0;
}
全部回答
- 1楼网友:冷眼_看世界
- 2021-03-06 08:14
定义一个26元素的整型数组。
- 2楼网友:ー何必说爱
- 2021-03-06 07:14
#include <stdio.h>
int main()
{
int count[26]={0},i;
char c;
while((c=getchar())!='\n')
if(c>='a'&&c<='z')
count[c-'a']++;
for(i=0;i<26;i++)
printf("%c : %d\n",i+'a',count[i]);
return 0;
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯