输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
4条回答 默认 最新
- threenewbee 2017-10-31 01:55关注
#include <stdio.h> int main() { char c; int letters=0,space=0,digit=0,other=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 { other++; } } printf("字母数:%d\n空格数:%d\n数字数:%d\n其他字符:%d\n",letters,space,digit,other); return 0; } 结果: 请输入一行字符:I am a student 666. 字母数:11 空格数:4 数字数:3 其他字符:1 请按任意键继续. . .
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 shape_predictor_68_face_landmarks.dat
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 对于相关问题的求解与代码
- ¥15 ubuntu子系统密码忘记
- ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
- ¥15 保护模式-系统加载-段寄存器
- ¥15 电脑桌面设定一个区域禁止鼠标操作
- ¥15 求NPF226060磁芯的详细资料
- ¥15 使用R语言marginaleffects包进行边际效应图绘制