c程序设计第四版谭浩强
C语言: 输入一行文字 找出其中的大写字母、小写字母、空格、数字以及其他字符各有多少。
c程序设计第四版谭浩强课后答案
以下是此题的【c源代码】,需要【c++源代码】请点击进入
#include <stdio.h>
int main()
{int upper=0,lower=0,digit=0,space=0,other=0,i=0;
char *p,s[20];
printf("input string: ");
while ((s[i]=getchar())!='\n') i++;
p=&s[0];
while (*p!='\n')
{if (('A'<=*p) && (*p<='Z'))
++upper;
else if (('a'<=*p) && (*p<='z'))
++lower;
else if (*p==' ')
++space;
else if ((*p<='9') && (*p>='0'))
++digit;
else
++other;
p++;
}
printf("upper case:%d lower case:%d",upper,lower);
printf(" space:%d digit:%d other:%d\n",space,digit,other);
return 0;
}
本文链接:http://www.wb98.com/c/post/tanhaoqiang_8.8.html
本站文章搜索: