当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机二级C语言上机操作题及答案(72)
发布时间:2011/7/20 13:21:50 来源:城市学习网 编辑:ziteng
  一、填空题
  请补充main函数,该函数的功能是:计算三个学各科的平均分。
  例如:当score=[N][M]={{78.5,84,83,65,63},{88,91.5,89,93,95},{72.5,65,56,75,77}}时,五科的平均分为:79.7 80.2 76.0 77.7 78.3。
  仅在横线上填入所编写的若干表达式或语句,勿改动函数中的其它任何内容。
  其源代码如下:
  #include
  #define  N 3
  #define  M 5
  main()
  {
  int  i, j;
  static float  score[N][M] =
  {
  {78.5, 84, 83, 65, 63},
  {88, 91.5, 89, 93, 95},
  {72.5, 65, 56, 75, 77}
  };
  static float  bb[N];
  for (i=0; i  bb[i] = 0.0;
  for (i=0; i<___1___; i++)
  for (j=0; j<___2___; j++)
  bb[j] += score[i][j];
  for (i=0; i  printf("\nsubject%d\taverage=%5.1f", i+1, ___3___);
  return 0;
  }[NextPage]   二、改错题
  下列给定程序函数fun的功能是:统计子字符串substr在字符串str中出现的次数。例如,若字符串aaas lkaaas,子字符串为as,则应输出2。
  请改正程序中的错误,使它能得出正确的结果。
  注意:不要改动main函数,不得增行或删除行,也不得更改程序的结构。
  源程序如下:
  #include
  /********found********/
  int fun(char  *str, *substr)
  {
  int  i, j, k, num = 0;
  /********found********/
  for (i=0, str[i], i++)
  for (j=i, k=0; substr[k]==str[j]; k++, j++)
  if (substr[k+1] == '\0')
  {
  num++;
  break;
  }
  return num;
  }
  main()
  {
  char  str[80], substr[80];
  printf("Input a string:");
  gets(str);
  printf("Input a substring:");
  gets(substr);
  printf("%d\n", fun(str, substr));
  }
[NextPage]   三、编程题
  请编写函数fun,其功能是:将s所指字符串中下标为偶数的字符删除,串中剩余字符形成的新串放在t所指数组中。
  例如,当s所指字符串中的内容为ABCDEFGHIJK,则在t所指数组中的内容应是:BDFHJ。
  请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
  源代码如下:
  #include
  #include
  #include
  void fun( char *s, char t[])
  {
  }
  main()
  {
  char s[100], t[100], Msg[] = "\nPlease enter string S:";
  FILE  *out;
  printf(Msg);
  scanf("%s", s);
  fun(s,t);
  printf("\nThe result is :%s\n", t);
  out=fopen ("out.dat", "w");
  fun(Msg, t);
  fprintf(out, "%s", t);
  fclose (out );
  }
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved