甲秀又一村新浪博客:编写函数long fun(long x)

来源:百度文库 编辑:神马品牌网 时间:2024/05/01 06:56:58
它的功能是:将长整型参数x中每一位上为偶数的数依次取出,构成一个新数返回.高位仍在高位,低位仍在低位.例如,下面程序运行时输入:124578902,程序输出:24802.

main()
{
long fun();
long a;
a=124578902;
fun(a);
getch();
}
long fun(long x)
{
long i=0;
int j=0;
int v[100];
for(j=0;j<100;j++)
v[j]=0;
j=0;
while((x/10)>=1)
{
i=x%10;
if (i%2==0) {v[j]=i;j++;}

x=x/10;
}
if (x%2==0) v[j]=x;
else j--;
for(;j>=0;j--)
printf("%d",v[j]);
return 0;
}