2013年计算机二级C语言上机试题二十九及答案

2014-11-01 17:15:08 · 作者: · 浏览: 56

  填空题
  请补充fun函数,该函数的功能是求不超过给定自然数的各偶数之和。
  请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句。
  试题程序:#include
  int fun(int x)
  {
  int i, s;
  s = ___1___;
  for (i=2; ___2___; i+=2)
  s += i;
  return s;
  }
  main()

  {
  int n;
  do
  {
  printf("\nPlease enter natural numbers n:");
  scanf("%d", &n);
  } while (n <= 0);
  printf("\n2 3 1y ¨× è êy%dμ ÷ êy oí a%d\n", n, fun(n));
  }
  第1处填空:0
  第2处填空:i<=x或x>=i