填空题 C语言
题号 #2256693

请补充main()函数,该函数的功能是:从字符串str中取出所有数字字符,并分别计数,然后把结果保存在数组tt 中并输出,把其他字符保存在tt[10]中。
例如,当strl=“00237481367539dfji”时,结果为
0:2 1:l 2:1 3:3 4:1 5:1 6:1 7:2 8:1 9:1 other charac—tor:4
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在横线上填人所编写的若十表达式或语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int i,tt[11];
char*str="00237481367539dfji";
char*p=str;
system("CLS"):
printf("***the origial data***\n");
puts(str);
for(i=0;i<11;i++)
tt[i]=0;
while(*p)
{
switch(【1】)
{
case'0 ':tt[0]++;break;
case'1':tt[1]++;break;
case'2':tt[2]++;break;
case'3':tt[3]++;break;
case'4':tt[4]++;break;
case'5':tt[5]++;break;
case'6':tt[6]++;break;
case'7':tt[7]++;break;
case'8':tt[8]++;break;
case'9':tt[9]++;break;
【2】
}
【3】
}
printf("***{the result****\n");
for(i=0;i<10;i ++)
printf("\n%d:%d",i,tt[i]);
printf("\nother{、haractor:%d",tt[i]);
}

进入在线模考

参考答案

暂无

答案解析

【1】*P【2】default:tt[10]++;【3】p++;
【解析】由整个switch语句可知,该语句的功能为判断字符串str中每一个字符,因此_【1】处填“*P”;按照题目中要求,将所有非数字字符放在tt[10]中,因此,【2】处填“de
fault:tt[10]++;”;指针变量P指向字符串str中每一个字符,每一次循环,p向后移动一个位置,因此,【3】处填“p ++;”。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考