【指针】18.输入一行文字,找出其中大写字母,小写字母,空格,数字以及其他字符各有多少?

【指针】18.输入一行文字,找出其中大写字母,小写字母,空格,数字以及其他字符各有多少?,第1张

指针】18.输入一行文字,找出其中大写字母,小写字母,空格,数字以及其他字符各有多少?

【题目】

 

【源代码】

#include
#include
int main()
{
	char a[100];
	char *p;
	int u=0,l=0,s=0,d=0,o=0;	
	gets(a);
	p=a;
	for(;*p!='';p++)//for循环用指针!!! 
	{
		if(*p>='A'&&*p<='Z')
			u++;
		else if(*p>='a'&&*p<='z')
			l++;
		else if(*p==' ')
			s++;
		else if(*p>='0'&&*p<='9')
			d++;
		else o++;
	}

	printf("upper case:%dn",u);
	printf("lower case:%dn",l);
	printf("space:%dn",s);
	printf("digit:%dn",d);
	printf("other:%dn",o);
	
	return 0;	
}

【运行结果】

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/3970220.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-21
下一篇 2022-10-21

发表评论

登录后才能评论

评论列表(0条)

保存