公众号【C you again】回复 “浙大版C语言” 查看每道题目详细实现思路
公众号【C you again】回复 “编程交流群” 进C/C++/Java编程题交流、问题解答群
本题要求编写程序,输入10个字符,统计其中英文字母、空格或回车、数字字符和其他字符的个数。
输入格式:
输入为10个字符。最后一个回车表示输入结束,不算在内。
输出格式:
在一行内按照
letter = 英文字母个数, blank = 空格或回车个数, digit = 数字字符个数, other = 其他字符个数
的格式输出。
输入样例:
aZ &
09 Az
输出样例:
letter = 4, blank = 3, digit = 2, other = 1
代码:
#include<stdio.h>
int main()
{
char str[10];
int i;
int letter=0;
int blank=0;
int digit=0;
int other=0;
for(i=0;i<10;i++)
{
scanf("%c",&str[i]);
if(str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z') letter++;
else if(str[i]==' '||str[i]=='
') blank++;
else if(str[i]>='0'&&str[i]<='9') digit++;
else other++;
}
printf("letter = %d, blank = %d, digit = %d, other = %d
",letter,blank,digit,other);
return 0;
}
作者: C you again,从事软件开发 努力在IT搬砖路上的技术小白
公众号:【
C you again】分享计算机类毕业设计源码、IT技术文章、游戏源码、网页模板、程序人生等等。公众号回复 【
粉丝】进博主技术群,与大佬交流,领取干货学习资料
关于转载:欢迎大家转载本文,转载时表明出处
求赞环节:创作不易,记得
点赞+
评论+
转发
,谢谢你一路支持