About the even simpler method of removing and re-output. (Cont.)

Benpian continued homepage excluded even-papers

Specific issues and a detailed explanation see above article,

Data in this chapter speak with the most convenient way, a minimum of code to achieve our objective.

(Of course, you may also have other good way. I hope we shall remind, in order to improve the latter part of this article)

The approach here we probably speak two

1: no array, i.e., sequentially determining from the forward, to give the first odd-numbered by 1, the second multiplied by 10, are sequentially processed, the results are added. When judged complete output to the most significant bit out of the loop.

2: an array: i.e., from the back, did not give an odd sequence into an array, and finally reverse order output.

For that matter, I still recommend using cyclic resolved. Because the definition becomes an issue, then an array of array length, in vain would take up too much memory is too long, too short, fear of bounds.

So here only for the first method for encoding, the second we can bring to practice your hand, try to beat yourself.

#include<stdio.h>
int main ()
{
int x,sum=0,a,s=1,y;
scanf("%d",&x);
for(a=x;a!=0;a/=10)
{
y = 10%;
if(y%2==1)
{
sum=y*s+sum;
s*=10;
}
}
printf("%d\n",sum);
return 0;
}
So only one cycle to the outcome. It will be a lot easier.
The sequel finished OK, what deficiencies in the hope a lot to say that I would be improved and adjusted.

Guess you like

Origin www.cnblogs.com/cndccm/p/11854244.html