C语言:文章各类字符数统计

一篇文章共3行,每行80个字符,统计出其英文大写字母,英文小写字母,数字,空格,其他字符的个数

#include<stdio.h>
#include <stdlib.h>
int main(){
	char text[3][80];
    int i,j,a,b,c,d,e;
    a=b=c=d=e=0;
    for(i=0;i<3;i++){
		printf("请输入第%d行\n",i+1);
		gets(text[i]);    							//二维数组用gets()的输入方法
		for(j=0;j<80 && text[i][j]!='\0';j++){      //字符数组最后要&&上text[i][j]!='\0'来确定结尾
			if (text[i][j]>='A' && text[i][j]<='Z') 		a++;
			else if (text[i][j]>='a' && text[i][j]<='z') 	b++;
			else if (text[i][j]>='0' && text[i][j]<='9')	c++;
			else if (text[i][j] == ' ') 					d++;
			else 											e++;
		}
    }
	printf("大写字母个数为:%d\n",a);
	printf("小写字母个数为:%d\n",b);
	printf("数字个数为:%d\n",c);
	printf("空格个数为:%d\n",d);
	printf("其他字符个数为:%d\n",e);
	

	printf("\n");
	system("pause");
	return 0;
}

运行结果为:
在这里插入图片描述

  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值