当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机二级C语言上机题库及答案(49)
发布时间:2011/9/16 11:23:18 来源:城市学习网 编辑:ziteng
  一、填空题:甲乙丙丁四人同时开始放鞭炮,甲每隔t1秒放一次,乙每隔t2秒放一次, 丙每隔t3秒放一次,丁每隔t4秒放一次,每人各放n次。函数fun的功能是根据形参提供的值,求出总共听到多少次鞭炮声作为函数值返回。注意,当几个鞭炮同时炸响,只算一次响声,第一次响声是在第0秒。

  例如,若t1=7,t2=5,t3=6,t4=4,n=10,则总共可听到28次鞭炮声。

  请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。

  注意:源程序存放在考生文件夹下BLANK1.C中。

  不得增行或删行,也不得更改程序的结构!

  给定源程序:

  #include

  /**********found**********/

  #define OK(i, t, n) ((___1___%t==0) && (i/t

  int fun(int t1, int t2, int t3, int t4, int n)

  {int count, t , maxt=t1;

  if (maxt < t2) maxt = t2;

  if (maxt < t3) maxt = t3;

  if (maxt < t4) maxt = t4;

  count=1; /* 给count赋初值 */

  /**********found**********/

  for(t=1; t< maxt*(n-1); ___2___)

  {

  if(OK(t, t1, n) || OK(t, t2, n)|| OK(t, t3, n) || OK(t, t4, n))

  count++;

  }

  /**********found**********/

  return ___3___;

  }

  main()

  {int t1=7, t2=5, t3=6, t4=4, n=10, r;

  r = fun(t1, t2, t3, t4, n);

  printf("The sound : %d\n", r);

  }

  解题答案:

  /**********found**********/

  for(t=1; t< maxt*(n-1); t++)

  /**********found**********/

  return count;

  ****************************************** [NextPage]   二、改错题:给定程序MODI1.C中函数fun的功能是: 根据输入的三个边长(整型值), 判断能否构成三角形; 构成的是等边三角形, 还是等腰三角形。若能构成等边三角形函数返回3,若能构成等腰三角形函数返回2, 若能构成一般三角形函数返回1, 若不能构成三角形函数返回0。

  请改正函数fun中指定部位的错误, 使它能得出正确的结果。

  注意: 不要改动main函数, 不得增行或删行, 也不得更改程序的结构!

  给定源程序:

  #include

  #include

  /**************found**************/

  void fun(int a,int b,int c)

  {if(a+b>c && b+c>a && a+c>b) {

  if(a==b && b==c)

  return 3;

  else if(a==b||b==c||a==c)

  return 2;

  /**************found**************/

  else return 1

  }

  else return 0;

  }

  main()

  {int a,b,c,shape;

  printf("\nInput a,b,c: "); scanf("%d%d%d",&a, &b,&c);

  printf("\na=%d, b=%d, c=%d\n",a,b,c);

  shape =fun(a,b,c);

  printf("\n\nThe shape : %d\n",shape);

  }

  解题答案:

  /**************found**************/

  int fun(int a,int b,int c)

  /**************found**************/

  else return 1;

  ******************************************

 [NextPage]   二、改错题:给定程序MODI1.C中函数fun的功能是: 根据输入的三个边长(整型值), 判断能否构成三角形; 构成的是等边三角形, 还是等腰三角形。若能构成等边三角形函数返回3,若能构成等腰三角形函数返回2, 若能构成一般三角形函数返回1, 若不能构成三角形函数返回0。

  请改正函数fun中指定部位的错误, 使它能得出正确的结果。

  注意: 不要改动main函数, 不得增行或删行, 也不得更改程序的结构!

  给定源程序:

  #include

  #include

  /**************found**************/

  void fun(int a,int b,int c)

  {if(a+b>c && b+c>a && a+c>b) {

  if(a==b && b==c)

  return 3;

  else if(a==b||b==c||a==c)

  return 2;

  /**************found**************/

  else return 1

  }

  else return 0;

  }

  main()

  {int a,b,c,shape;

  printf("\nInput a,b,c: "); scanf("%d%d%d",&a, &b,&c);

  printf("\na=%d, b=%d, c=%d\n",a,b,c);

  shape =fun(a,b,c);

  printf("\n\nThe shape : %d\n",shape);

  }

  解题答案:

  /**************found**************/

  int fun(int a,int b,int c)

  /**************found**************/

  else return 1;

  ******************************************

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved