当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机二级C语言上机操作题及答案(6)
发布时间:2011/6/30 10:55:58 来源:城市学习网 编辑:ziteng
  第6套
  填空题
  给定程序的功能是计算并输出下列级数的前N项之和 SN,直到 SN大于Q为止,Q的值通过形参传入。
  例如,若Q的值为50.0,则函数值为50.416687。
  请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句。
  试题程序:#include
  double fun(double  q)
  {
  int  n;
  double  s;
  n = 2;
  s = 2.0;
  while (s ___1___ q)
  {
  s = s + (double)(n+1)/n;
  ___2___;
  }
  printf("n=%d\n",n);
  ___3___;
  }
  main()
  {
  printf("%f\n", fun(50));
  }
  第1处填空:<=
  第2处填空:n++或n+=1或n=n+1
  第3处填空:return s或return (s) [NextPage]   改错题
  下列给定程序中,函数fun的功能是:根据整型参m的值,计算如下公式的值。
  例如,若m中的值为5,则应输出:0.536389
  请改正程序中的错误,使程序能得出正确的结果。
  注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
  试题程序:  #include
  #include
  double fun(int  m)
  {
  double  y = 1.0;
  int  i;
  /********found********/
  for (i=2; i       /********found********/
  y -= 1/(i*i);
  return(y);
  }
  main()
  {
  int  n = 5;
  printf("\nThe result is \n", fun(n));
  }
  第1处:for (i=2;i第2处:y-=1/(i*i);应改为y-=1.0/(i*i)
 
 [NextPage]   编程题
  请编写一个函数void fun(char a[],char b[],int n),其功能是:删除一个字符串中指定下标的字符。其中,a指向原字符串,删除后的字符串存放在b所指的数组中,n中存放指定的下标。
  例如,输入一个字符串World,然后输入3,则调用该函数后的结果为Word。
  注意:部分源程序给出如下。
  请勿改动主函数main和其他函数中的任何内容,仅在函数 fun 的花括号中填入所编写的若干语句。
  试题程序:  # include
  # include
  # define LEN 20
  void fun(char a[], char b[], int n)
  {
  }
  main()
  {
  char str1[LEN],str2[LEN];
  int n;
  FILE *out;
  printf("Enter the string:\n");
  gets(str1);
  printf("Enter the position of the string deleted:");
  scanf("%d",&n);
  fun(str1, str2, n);
  printf("The new string is:%s\n",str2);
  fun("Hello World!", str2, 9);
  out = fopen("out.dat", "w");
  fprintf(out, "%s", str2);
  fclose(out);
  }
  答案是:
  void fun(char a[], char b[], int n)
  {
  int  I,j=0;
  for(i=0;iif(i!=n)
  {
  b[j]=a[i];
  j++;
  }
  b[j]=’\0’;
  }
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved