c语言问题:求一句代码中的字母数,空格数,和标点符号数?
发布网友
发布时间:2024-10-04 20:43
我来回答
共3个回答
热心网友
时间:2024-10-05 07:43
#include<stdio.h>
void main()
{
int a=0,b=0,c=0,d=0;
char c1;
while((c1=getchar())!='\n')
{
if((c1>='a'&&c1<='z')||(c1>='A'&&c1<='Z')) a++;
else if(c1>='0'&&c1<='9') b++;
else if(c1==' ') c++;
else d++;
}
printf("%d,%d,%d,%d",a,b,c,d);
}
热心网友
时间:2024-10-05 07:38
#include <stdio.h>
int main()
{
char ch[60]="I love the beautiful life. Enjoy it, my friends!";
/*there are 8 blanks,1 comma,1 dot,1 exclamatory point*/
int letter=0,punctuation=0,blank=0;
for(int i=0;ch[i]!='\n';i++)
{
if( (ch[i]>32 && ch[i]<48 )||
(ch[i]>57 && ch[i]<65)||
(ch[i]>90 && ch[i]<97))
punctuation++;
if( ch[i]==' ')
blank++;
if( ch[i]>='a' && ch[i]<='z' ||
ch[i]>='A' && ch[i]<='Z')
letter++;
}
printf("%s\n",ch);
printf("letter=%d,blank=%d,puctuation=%d\n",letter,blank,punctuation);
}
热心网友
时间:2024-10-05 07:35
han 3