模拟试题

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

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

来源:2exam.com 2013-11-14 20:10:57

给定程序中,函数fun的功能是:找出100至x(x≤999)之间各位上的数字之和为15的所有整数,然后输出;符合条件的整数个数作为函数值返回。 

  例如,当n值为500时,各位数字之和为15的整数有:159、168、177、186、195、249、258、267、276、285、294、339、348、357、366、375、384、393、429、438、447、456、465、474、483、492。共有26个。 

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

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

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

  给定源程序: 

  #include  

  fun(int x) 

  { int n, s1, s2, s3, t; 

  n=__1__; 

  t=100; 

  while(t<=__2__) 

  { s1=t; s2=(t/10); s3=t/100; 

  if(s1+s2+s3==15) 

  { printf("%d ",t); 

  n++; 

  } 

  __3__; 

  } 

  return n; 

  } 

  main() 

  { int x=-1; 

  while(x>999||x<0) 

  { printf("Please input(0  printf("\nThe result is: %d\n",fun(x)); 

  } 

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