#include

#include

#define  N    100

void func3()

{

char str[N];

int i,lower=0,upper=0,digit=0,space=0;

long others=0;

printf("Input a string:");

gets(str);

for(i=0;str[i]!='\0';i++)

{

if(str[i]>='a' && str[i]<='z')

lower++;  /*统计小写英文字母*/

else if(str[i]>='A' && str[i]<='Z')

upper++;  /*统计大写英文字母*/

else if(str[i]>='0' && str[i]<='9')

digit++;  /*统计字符串*/

else if(str[i]==' ')

space++;

else

others++; /*统计其他字母*/

}

printf("lower English character:%d\n",lower);

printf("upper English character:%d\n",upper);

printf("digit character:%ld\n",digit);

printf("space:%d\n",space);

printf("other character: %ld\n",others);

return 0;

}

int main()

{

while(1)

{

func3();

printf("\n");

system("pause");

}

return 0;

}

扩展资料:

程序实现思路分析

统计大小写字母、数字的个数,首先要判断出字符是属于哪一种,然后增加计数。

1、判断

小写字母的范围为:'a'~'z'

大写字母的范围为:'A'~'Z'

数字的范围为:'0'~'9'

2、声明三个int变量并赋值初值为0

lower——统计小写英文字母

upper——统计大写英文字母

digit——统计数字

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐