c语言:从键盘输入一串字符,以-结束,统计其中的数字字符个数,小写字母个数.
展开全部
#include <stdio.h>
int main()
{
int i = 0;
char str[100];
for(i=0; i<100; ++i)
str[i] = ' ';
char ch;
i = 0;
;
while((ch = getchar())!='-')
{
str[i] = ch;
++i;
}
int len = i+1;
int num_num = 0;
int char_num = 0;
for(i=0; i<len; ++i)
{
if(str[i]>='0' && str[i]<='9')
num_num ++;
else if(str[i]>='a' && str[i]<='z')
char_num++;
}
printf("数字个数:%d\n", num_num);
printf("字符个数:%d\n", char_num);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询