将一个长整型数s的每一位数位上的偶数依次取出来,构成一个新的数t,其高位仍在高位,低位仍在低位
参考如下:
#include<stdio.h>
void convert(long s, long *t)
{
int d;
long temp=1;
*t = 0;
while (s > 0)
{
d = s%10; // 取余,获取最后一位数
if(d%2==0) // 是偶数
{
*t += d * temp;
temp *= 10;
}
s/=10;
}
}
int main()
{
long s, t;
printf("Please enter s:");
scanf("%ld", &s);
convert(s, &t);
printf("The result is: %ld\n", t);
return 0;
}