C语言编程>第二十二周 ⑦ 下列给定程序中函数fun的功能是:从低位开始取出长整型变量a中奇数位上的数,依次构成一个新数放在b中。

例题:下列给定程序中函数fun的功能是:从低位开始取出长整型变量a中奇数位上的数,依次构成一个新数放在b中。

例如,当a中的数为7654321时,则b中的数为7531。
注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。

代码如下:

#include<conio.h>
#include<stdio.h>
void fun(long a,long*b)
{
    
    
	long s1=10;
	*b=a%10;
	while(a>0)
	{
    
    
		a=a/100;
		*b=a%10*s1+*b;
		s1=s1*10;
	}
}
main()
{
    
    
	long a,b;
	printf("\nPlease enter data:");
	scanf("%ld",&a);
	fun(a,&b);
	printf("The result is:%ld\n",b);
}

输出运行窗口如下:
在这里插入图片描述

越努力越幸运!
加油,奥力给!!!

猜你喜欢

转载自blog.csdn.net/qq_45385706/article/details/112801863