当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机二级C语言上机操作题及答案(19)
发布时间:2011/7/8 11:30:50 来源:城市学习网 编辑:ziteng
  第19套
  填空题
  给定程序的功能是计算SCORE中M个人的平均成绩AVER,将低于AVER的成绩放在BELOW中,通过函数名返回人数。
  例如,当SCORE={10,20,30,40,50,60,70,80,90},M=9时,函数返回人数应该是4,BELOW={10,20,30,40}。
  注意:部分源程序给出如下
  请勿改动主函数main和其他函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。
  试题程序:#include <stdio.h>
  #include <string.h>
  int fun(int  score[], int  m, int  below[])
  {
  int  i, j = 0;
  float  aver = 0.0;
  for (i=0; i<m; i++)
  aver += score[i];
  aver /= (float)m;
  for (i=0; i<m; i++)
  if (score[i] < aver)
  below[j++] = ___1___;
  return j;
  }
  main()
  {
  int  i, n, below[9];
  int  score[9] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
  n = fun(score, 9, ___2___);
  printf("\nBelow the average score are: ");
  for (i=0; i<n; i++)
  printf("%d ", ___3___);
  }
  第1处填空:score[i]或*(score+i)
  第2处填空:below
  第3处填空:below[i]或*(below+i) [NextPage]   改错题
  下列给定程序中函数FUN的功能是:从低位开始取出长整型变量S中偶数位上的数依次构成一个新数放在T中。例如,当S中的数为7654321时,T中的数为642。
  请改正程序中的错误,使它能得出正确结果。
  注意:不要改动MAIN函数,不得增行或删行,也不要更改程序的结构!
  试题程序:#include <conio.h>
  #include <stdio.h>
  /********found********/
  void fun(long  s, long  t)
  {
  long  s1 = 10;
  s /= 10;
  *t = s%10;
  /********found********/
  while (s < 0)
  {
  s = s/100;
  *t = s%10*s1+*t;
  s1 = s1*10;
  }
  }
  main()
  {
  long  s, t;
  printf("\nPlease enter s:");
  scanf("%ld", &s);
  fun(s, &t);
  printf("The result is:%ld\n", t);
  }
  第1处:void fun(long s,long t) 应改为void fun(long s,long *t)
  第2处:while(s<0)应改为while(s>0)
 [NextPage]   编程题
  请编写fun函数,函数的功能是:从字符串中删除指定的字符,同一字母的大,小写按不同的字母处置,
  例如:若程序执行时输入字符串为:turbo c and borland c++
  从键盘上输入字符n,则输出后变为:turbo c ad borlad c++
  如果输入 的字符在字符串中不存在,则照原样输出
  注意:部分源程序给出如下。
  请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
  试题程序:
  #include <stdio.h>
  #include <string.h>
  void fun(char s[],int c)
  {
  }
  main()
  {
  static char str[]="turbo c and borland c++";
  char ch;
  FILE *out;
  printf("?-ê?×?·?′?:%s\n",str);
  printf("ê?è?ò???×?·?:");
  scanf("%c",&ch);
  fun(str,ch);
  printf("str[]=%s\n",str);
  strcpy(str, "turbo c and borland c++");
  fun(str, 'a');
  out = fopen("out.dat", "w");
  fprintf(out, "%s", str);
  fclose(out);
  }
  答案是:
  void fun(char s[],int c)
  {
  int i=0;
  char *p;
  p=s;
  while(*p)
  {
  if(*p!=c)
  {
  s[i]=*p;
  i++;
  }
  p++;
  }
  s[i]=’\0’;
  }
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved