2013年计算机二级C语言上机题库四十二

考试站(www.examzz.com)   【考试站:中国教育考试第一门户】   2013年6月3日

为方便广大考生更好的复习2013年计算机二级C语言考试,查找考试辅导习题,考试站(www.examzz.com)网校特提供了C语言上机预测题(填空题、改错题、编程题),更多模拟无纸化考试“计算机二级C语言模拟题”,供考生学习。

填空题
  请补充main函数,该函数的功能是:从字符串str中取出所有数字字符, 并分别计数,
  并把结果保存在数组b中并输出,把其它字符保存在b[10]中.
  例如:当str=”de123456789abc0908”时,结果为: 0: 2 1: 1 2: 1 3: 1 4: 1 5: 1 6: 1 7: 1 8:
  2 9: 2 other character: 5.
  仅在横线上填入所编写的若干表达式或语句,勿改动函数中的其它任何内容.
  #include <stdio.h>
  #include <conio.h>
  main()
  {
  int i, b[11];
  char *str = "de123456789abc0908";
  char *p = str;
  printf("****** the origial data ********\n");
  puts(str);
  for (i=0; i<11; i++)
  b[i] = 0;
  while (*p)
  {
  switch (*p)
  {
  case '0':
  b[0]++;
  break;
  case '1':
  b[1]++;
  break;
  case '2':
  b[2]++;
  break;
  case '3':
  b[3]++;
  break;
  case '4':
  b[4]++;
  break;
  case '5':
  b[5]++;
  break;
  case '6':
  b[6]++;
  break;
  case '7':
  b[7]++;
  break;
  case '8':
  b[8]++;
  break;
  case '9':
  b[9]++;
  break;
  default: b[10]++;break;
  }
  p++;
  }
  printf("****** the result ********\n");
  for (i=0; i<10; i++)
  printf("\n%d:%d", i, b[i]);
  printf("\nother character:%d", b[i]);
  }


首页 1 2 3 尾页

相关文章