c语言编程,把输入的内容进行分类并统计数量代码

30 阅读1分钟

#include <stdio.h> #include <stdlib.h> int main() {char c; int letters=0,space=0,digit=0,others=0; printf("please input some characters请输入一些字符\n"); while((c=getchar())!='\n') { if(c>='a'&&c<='z'||c>='A'&&c<='Z') letters++; else if(c=='\0') space++; else if(c>='0'&&c<='9') digit++; else others++; } printf("all in all总计:char字符=%d,space空格=%d,digit数字=%d,others其他=%d\n",letters,space,digit,others); }