您的位置:首页 > 其它

94.取出长整型各位为奇数的数组成一个新的数

2015-07-03 15:26 239 查看
函数fun的功能是:将长整型数中每一位上为奇数的数依次取出,构成一个新书放在t中,高位仍在高位,低位仍在低位。

</pre><pre name="code" class="cpp">#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void fun(long s, long *t)
{
int d;
long s1 = 1;
*t = 0;
while (s > 0)
{
d = s % 10;
if (d % 2 != 0)
{
*t = d*s1 + *t;
s1 *= 10;
}
s /= 10;
}
}
int main()
{
long s, t;
printf("\nPlease enter s:");
scanf("%ld", &s);
fun(s, &t);
printf("The result is :%ld\n", t);
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: