#include <stdio.h>
#include <stdlib.h>
#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=0str[i]!='\0'i++)
{
if(str[i]>='a' &&str[i]<='z')
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——统计数字
#include<stdio.h>void
main()
{
int
m=0
char
c
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z')
m++
}
printf("小写字母个数为:%d\n",m)
}
不用楼上们说的那麽麻烦吧,给你设计个简单的,我试验过了,没问题的,你试试。呵呵,祝你好运!