编写一函数,将形参n中各位上为偶数的数取出,按原来从高到低位的顺序组成一个新的数,并作为函数值返回。
#include “stdio.h”
#include “math.h”
int f(int n)
{ int s=0,k=0,r;
do
{ r=n%10;
if(r%2==0){s+=r*pow(10,k);k++;}
n=n/10;
}while(n);
return s;
}
void main()
{ int n;
printf(“请输入一个正整数”);
scanf(“%d”,&n);
printf(“%d的偶数码按原来从高到低位的顺序组成的新整数为%d\n”,n,f(n));
}
© 版权声明
部分文章来自网络,只做学习和交流使用,著作权归原作者所有,遵循 CC 4.0 BY-SA 版权协议。
THE END




![ps色相/饱和度使用教程——在[色相/饱和度]对话框中指定调整的颜色范围-伊丞小站(YLIMHS.COM)](https://www.ylimhs.com/wp-content/uploads/2020/05/20200504_5eb02afdd8bcc.png)



暂无评论内容