[C]字符统计

C语言统计英文字母、空格、数字和其它字符的数目

  #define _CRT_SECURE_NO_WARNINGS 1
    
    #include <stdio.h>
    
    int main()
    {
    	char c;
    	int letters = 0,
    		space = 0,
    		digit = 0,
    		others = 0;
    	printf("请输入字符串>:");
    	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
    			others++;
    	}
    	printf("\n统计结果:\n英文字母=%d\n空格=%d\n整数=%d\n其他字符=%d\n\n", letters, space, digit, others);
    	return 0;
    }

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/quchen528/article/details/83386861