问题 填空题

下列给定程序中函数fun()的功能是:将长整型数中每一位上为偶数的数依次逆向取出,构成一个新数放在t中。高位在低位,低位在高位。例如当s中的数为25846513时,t中的数为6482。
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <conio.h>
void fun(long s,long *t)

int d;
long sl=l,i=1;
*t=0;
while(s/i>0)
i=i*10;
i=i/10;
while(s>0)

d=s/i
/*************found*************/
if(d%2!=0)

/*************found*************/
t=d*sl+t;
sl*=l0;

s=s%i;
i=i/10;


main()

long s,t;
clrscr();
printf("\nPlease enter s:");
scanf("%ld",&s);
fun(s,&t);
printf("The result is:%ld\n",t);

答案

参考答案:(1)错误:if(d%2!=0) 正确:if(d%2==0)
(2) 错误:t=d*s1+t; 正确:*t=d*s1+*t;

解析: 错误1:偶数是能被2整除,而奇数是不能被2整除,题目要求找出偶数。错误2:t为指针类型,所以进行运算时要加‘*’号。

单项选择题
选择题