天天看點

94.取出長整型各位為奇數的數組成一個新的數

函數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;
}