解题思路:
分四个变量统计就行
注意事项:
为什么回车不算字符
为什么回车不算字符
为什么回车不算字符
参考代码:
#include <stdio.h> int main() { char ch; int letter = 0; int number = 0; int space = 0; int other = 0; while (scanf("%c", &ch)!=EOF && ch != '\n') { if (ch == ' ') space++; else if (ch <= '9' && ch >= '0') number++; else if ((ch <= 'z' && ch >= 'a') || (ch <= 'Z' && ch >= 'A')) letter++; else other++; } printf("%d %d %d %d\n", letter, number, space, other); return 0; }
0.0分
5 人评分
C语言程序设计教程(第三版)课后习题5.7 (C++代码)浏览:706 |
【排队买票】 (C语言代码)浏览:805 |
Hello, world! (C++代码)浏览:1427 |
【C语言训练】自由落体问题 (C语言代码)浏览:506 |
C语言程序设计教程(第三版)课后习题9.3 (C语言代码)浏览:1884 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:329 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:430 |
整数平均值 (C语言代码)浏览:667 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:393 |
数列排序 (C语言代码)浏览:544 |
ET 2019-03-29 15:58:02 |
C++兼容C