C语言输入一行字符,分别统计出其中英文字母、空格、数字与其它字符得个数。

#include<stdio.h>
void main()
{
	char c;
	int letter = 0, space = 0, digit = 0, other = 0;
	printf("请输入需要统计的字段:\n");
	while ((c = getchar()) != '\n')//运用getchar逐个识别,回车结束
	{
		if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')
			letter++;
		else if (c == ' ')
			space++;
		else if (c >= '0' && c <= '9')
			digit++;
		else
			other++;
	}
	printf("letter=%d\nspace=%d\ndigit=%d\nother=%d", letter, space, digit, other);
}

posted @   放氮气的蜗牛  阅读(319)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示