填空题 下列给定程序中,函数fun()的功能是:将长整型数中各位上为奇数的数依次取出,构成一个新数放在t中。高位仍在高位,低位仍在低位。
例如,当s中的数为87653142时,t中的数为7531。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void fun(long s,long*t)
{
int d;
long s1=1;
//****found****
t=0;
while(s>0)
{
d=s%10;
//****found****
if(d%2==0)
{
*t=d*s1+*t;
s1*=10;
}
s/=10;
}
}
void main()
{
long s,t;
system("CLS");
printf("/nPlease enter s:");
scanf("%id",&s);
fun(s,&t);
printf("The result is:%id/n",t);
}
【正确答案】
【答案解析】错误:t=0;
正确:*t=0;
错误:if(d%2==0)
正确:if(d%2!=0)或if(d%2==1)