请高手过来,帮老弟解决一下。
C语言要完成的小程序求一个数字的每位是奇数的数字取出来组合形成的新数字。
要能运行的程序!!!!
程序代码:
root@~ #cat oddsum.c
#include <stdio.h>
int main (void) {
int n;
int res (int n);
scanf("%i",&n);
printf("%i\n",res(n));
return 0;
}
int res (int n) {
int sum=0,i=0,b=1;
do {
if((n%10)%2!=0) {
sum+=(n%10)*b;
b*=10;
}
n/=10;
}while(n!=0);
return sum;
}
root@~ #./oddsum
2134234
133
root@~ #./oddsum
2346578
357
root@~ #
