C语言程序设计(慕课版 第2版)综合自测题4答案.docxVIP

  • 0
  • 0
  • 约2.32千字
  • 约 6页
  • 2026-09-17 发布于四川
  • 举报

C语言程序设计(慕课版 第2版)综合自测题4答案.docx

C语言程序设计(慕课版第2版)综合自测题4答案

```c

includestdio.h

includestdlib.h

includestring.h

//题目1:编写一个程序,实现输入一个字符串,统计并输出其中字母、数字、空格和其他字符的数量。

voidcount_chars(){

charstr[100];

intletters=0,digits=0,spaces=0,others=0;

printf(Enterastring:);

fgets(str,sizeof(str),stdin);//使用fgets读取字符串,包括空格

for(inti=0;str[i]!=\0;i++){

if((str[i]=astr[i]=z)||(str[i]=Astr[i]=Z)){

letters++;

}elseif(str[i]=0str[i]=9){

digits++;

}elseif(str[i]==){

spaces++;

}else{

文档评论(0)

1亿VIP精品文档

相关文档