设为首页 加入收藏

TOP

2013年计算机二级C语言上机试题四十二及答案
2014-11-23 19:06:36 】 浏览:2327
Tags:2013年 计算机 二级 语言 上机 试题 四十二 答案

  填空题
  请补充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
  #include
  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]);
  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇2013年计算机二级C语言上机试题四.. 下一篇2013年计算机二级C语言上机试题四..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目