学习目标:
输入英文标题,统计大写字母、小写字母、数字和其他字符的个数。
学习内容:
1了解大小写字母、数字和其他字符的Ascall码。
2.学会使用getchar():从键盘读入一个字符。
3.熟练运用for循环语句和if选择语句。
代码:
#include <stdio.h>#include <stdlib.h>int main() {int a = 0;//大写字母int b = 0;//小写字母int c = 0;//数字int d = 0;//其他字符char ch;for (; (ch = getchar()) != EOF;) //输入Ctrl+Z结束运行{if (ch >= 65 && ch <= 90) {a++;}else if (ch >= 97 && ch <= 122) {b++;}else if (ch >= 48 && ch <= 57) {c++;}else if (ch == 10) {break;}else {d++;}}printf("大写字母:%d\n小写字母:%d\n数字:%d\n其他字符%d", a, b, c, d);return 0;}