数组 输入3行英文,输出其中字母、空格及其他字符出现的个数。
展开全部
//已在vc6.0中编译通过,最后附上运行结果,自我感觉比楼上的好
#include <stdio.h>
void main()
{
int letter=0,space=0,other=0;
int row=0;
char c;
while(c=getchar())
{
if(c=='\n')
{
row++;
if(row==3)
break;
else
continue;
}
if(row==3)
break;
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
letter++;
else if(c==' ')
space++;
else
other++;
}
printf("letters number:%d\nspaces number:%d\nothers number:%d\n",letter,space,other);
}
/*
asdf a sdf asdjf alsjdfl
12 1 3 23 2 1 2 13 asd f asd fas 3 2 ds af
23 sad fas df0 sf s adfl2 3l1 20 12 l 21 dsaf1as3
letters number:57
spaces number:35
others number:27
*/
#include <stdio.h>
void main()
{
int letter=0,space=0,other=0;
int row=0;
char c;
while(c=getchar())
{
if(c=='\n')
{
row++;
if(row==3)
break;
else
continue;
}
if(row==3)
break;
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
letter++;
else if(c==' ')
space++;
else
other++;
}
printf("letters number:%d\nspaces number:%d\nothers number:%d\n",letter,space,other);
}
/*
asdf a sdf asdjf alsjdfl
12 1 3 23 2 1 2 13 asd f asd fas 3 2 ds af
23 sad fas df0 sf s adfl2 3l1 20 12 l 21 dsaf1as3
letters number:57
spaces number:35
others number:27
*/
展开全部
#include <stdio.h>
void main()
{
int letter=0,space=0,other=0;
int i;
char s1[100],s2[100],s3[100];
gets(s1);
gets(s2);
gets(s3);
for(i=0;s1[i];i++)
{
if(s1[i]>='a'&&s1[i]<='z'||s1[i]>='A'&&s1[i]<='Z')letter++;
else if(s1[i]==' ')space++;
else other++;
}
for(i=0;s2[i];i++)
{
if(s1[i]>='a'&&s1[i]<='z'||s1[i]>='A'&&s1[i]<='Z')letter++;
else if(s1[i]==' ')space++;
else other++;
}
for(i=0;s3[i];i++)
{
if(s1[i]>='a'&&s1[i]<='z'||s1[i]>='A'&&s1[i]<='Z')letter++;
else if(s1[i]==' ')space++;
else other++;
}
printf("字母个数是%d.\n空格个数是%d.\n其他个数是%d.\n",letter,space,other);
}
void main()
{
int letter=0,space=0,other=0;
int i;
char s1[100],s2[100],s3[100];
gets(s1);
gets(s2);
gets(s3);
for(i=0;s1[i];i++)
{
if(s1[i]>='a'&&s1[i]<='z'||s1[i]>='A'&&s1[i]<='Z')letter++;
else if(s1[i]==' ')space++;
else other++;
}
for(i=0;s2[i];i++)
{
if(s1[i]>='a'&&s1[i]<='z'||s1[i]>='A'&&s1[i]<='Z')letter++;
else if(s1[i]==' ')space++;
else other++;
}
for(i=0;s3[i];i++)
{
if(s1[i]>='a'&&s1[i]<='z'||s1[i]>='A'&&s1[i]<='Z')letter++;
else if(s1[i]==' ')space++;
else other++;
}
printf("字母个数是%d.\n空格个数是%d.\n其他个数是%d.\n",letter,space,other);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询