编写函数long fun(long int x),功能是:将长整型数x中每一位上为奇数的数依次取出,并逆序构成一个新数返回。
例如:程序运行时输入123456789,输出:b=97531。
#include<stdio.h>
long fun(long int x)
{
long b=0;
while(x>0)
{
if((x%10)%2==1)
b=b*10+x%10;
x=x/10;
}
return b;
}
int main()
{ long a,b;
printf("Please input a long int num:");
scanf("%ld",&a);
b=fun(a);
printf("b=%ld\n",b);
return 0;
}