取奇数

2015-09-14 22:16:43 -0400
#include <stdio.h>
void fun(unsigned long *n) {
unsigned long x = 0, i;
int t;
i = 1;
while (*n)
/**********found**********/
{
t = *n % 10;//取个位
/**********found**********/
if (t % 2 != 0) {//如果为奇数
x = x + t * i;//加到末尾
i = i * 10;//位数往前移
}
*n = *n / 10;//减掉一位
}
/**********found**********/
*n = x;
}
int main(void) {
unsigned long n = -1;
while (n > 99999999 || n < 0) {
printf("Please input(0<n<100000000): ");
scanf("%ld", &n);
}
fun(&n);
printf("\nThe result is: %ld\n", n);
}
«Newer      Older»

----Comments(3)----
Wwrfcf (@sssdds) | @ at 2023-12-04 16:03:
Dd
落叶似秋 (@zyw8) | @ at 2019-06-05 12:04:
@fdbk 有些算法还是挺好理解的
意见反馈 (@fdbk) | @ at 2019-06-04 06:26:
要学习算法对我来说是不是天文数字呀?
Comment:
Name:

Back to home

Subscribe | Register | Login | N