1.
#include <stdio.h>
main()
{char c;
int letters=0,space=0,digit=0,other=0;
printf("please input chars:/n");
while((c=getchar())!='/n')
{if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else other++;
}
printf("letters=%d space=%d digit=%d other=%d/n",letters,space,digit,other);
}
2.
#include <stdio.h>
main()
{char c;
int letters=0,space=0,digit=0,other=0;
printf("please input chars:/n");
while((c=getchar())!='/n')
{if(c>='97'&&c<='122'||c>='65'&&c<='90')
letters++;
else if(c=='32')
space++;
else if(c>='48'&&c<='57')
digit++;
else other++;
}
printf("letters=%d space=%d digit=%d other=%d/n",letters,space,digit,other);
}
3.
c语言中的所有字符都是用asc码表示的,所以比较asc码肯定是正确的。另外记住'a'就是表示a的asc值等同于97