模拟试题

3773考试网计算机等级考试模拟试题正文

2014年3月全国计算机二级C语言上机模拟试题六十二2

来源:2exam.com 2013-11-12 16:21:33

解题思路: 

  第一处:for循环变量的增量,所以应填:i++。 

  第二处:由于右移m个位置,所以应填:m。 

  第三处:左边m列均置于0,所以for循环的终止值应为m。 

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

  给定程序MODI1.C中函数 fun 的功能是:计算并输出high以内最大的10个素数之和。high的值由主函数传给fun函数。若high的值为: 100, 则函数的值为: 732。 

  请改正程序中的错误,使程序能输出正确的结果。 

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

  给定源程序: 

  #include  

  #include  

  int fun( int high ) 

  { int sum = 0, n=0, j, yes; 

  while ((high >= 2) && (n < 10) 

  { yes = 1; 

  for (j=2; j<=high/2; j++ ) 

  if (high % j ==0 ){ 

  yes=0; break 

  } 

  if (yes) { sum +=high; n++; } 

  high--; 

  } 

  return sum ; 

  } 

  main ( ) 

  { 

  printf("%d\n", fun (100)); 

  }

触屏版 电脑版
3773考试网 琼ICP备12003406号-1