C语言编程题
程序填空题 给定程序中,函数fun的功能是:将形参n所指变量中,各位上为偶数的数去除,剩余的数按原来从高位到低位的顺序组成一个新的数,并通过形参指针n传回所指变量。
例如,输入一个数:27638496,新的数:为739。
#include <stdio.h>
/***********fun***************/
void fun(unsigned long *n)
{ unsigned long x=0, i; int t;
i=1;
while(*n)
{ t=*n % 10;
if(t%2)
{ x=x+t*i; i=i*10; }
*n =*n /10;
}
*n=x;
}
/*************fun***************/
int main()
{ 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);
}
运行示例
关注我,C语言不迷路。
需要分析可以到微信公众号发送问题或者在评论区留言,有问必答!
想了解我的C语言学习笔记等更多知识请关注公众号:
量子云基地