模拟试题

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

2013计算机二级C语言上机题库第三十三套及答案解析

来源:2exam.com 2013-6-20 9:15:57

 

 改错题
  给定程序MODI1.C中函数fun的功能是:将长整型数中每一位上为偶数的数依 次取出,构成一个新数放在t中。高位仍在高位,低位仍在低位。 例如,当s中的数为:87653142时,t中的数为:8642。 
  请改正程序中的错误,使它能得出正确的结果。 
  注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 
  给定源程序: 
  #include <stdio.h> 
  void fun (long s, long *t) 
  { int d; 
  long sl=1; 
  *t = 0; 
  while ( s > 0) 
  { d = s%10; 
  if (d%2=0) 
  { *t=d* sl+ *t; 
  sl *= 10; 
  } 
  s \= 10; 
  } 
  } 
  main() 
  { long s, t; 
  printf("\nPlease enter s:"); scanf("%ld", &s); 
  fun(s, &t); 
  printf("The result is: %ld\n", t); 
  } 
  解题思路: 
  第一处:判断相等的条件是==。 
  第二处:整除的符号是/。

上一页  [1] [2] [3] 下一页

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