用C语言写一个函数,要怎么用指针把奇数提取出来,然后再用这些奇数组成一串新的数 ?
2条回答 默认 最新
threenewbee 2018-10-28 04:12关注#include "stdio.h" void foo(int n, int * result) { *result = 0; int base = 1; while (n != 0) { if (n % 2 == 1) { *result += (n % 10) * base; base *= 10; } n /= 10; } } int main() { int n; scanf("%d", &n); int result; foo(n, &result); printf("%d\n", result); return 0; }
如果问题得到解决,请点我回答右边的采纳,谢谢本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 2无用