逆序偶数组合
请修改编辑器中的代码,完成以下功能:从键盘读入一个正整数 n(0 < n < 100000000),把其中所有数值为偶数的数字挑出来,按从低位到高位的顺序(即与原数相反的顺序)组成一个新的整数并输出。 注意判断的是数字本身的奇偶,不是它所在的位置;组合顺序是逆序。 初始代码中有 __1__、__2__、__3__ 三处需要填写。 输入示例: 12345678 输出示例: Please input(0<n<100000000): The result is: 8642
#include <stdio.h>
unsigned long fun(unsigned long n)
{ unsigned long x=0; int t;
while(n)
{ t=n%10;
if(t%2==__1__)
x=__2__+t;
n=__3__;
}
return x;
}
int main(void)
{ unsigned long n=-1;
while(n>99999999||n==0)
{ printf("Please input(0<n<100000000): "); if (scanf("%lu",&n) != 1) return 0; }
printf("\nThe result is: %lu\n",fun(n));
}
控制台
调试终端
