51 (take out the even numbers on the bits of the formal parameter n, and compose new numbers from high to low)

51 date: 2021.3.16
Insert picture description here
Key points:

The detailed code is as follows:

#include  <stdio.h>
unsigned long fun(unsigned long  n)
{
    
      unsigned long  x=0, s, i;   int  t;
   s=n;
/**********found**********/
   i= 1; 
/**********found**********/
   while(s>0)  //!!!
   {
    
      t=s%10;
      if(t%2==0){
    
    
/**********found**********/
         x=x+t*i;  i= i*10;
      }
       s=s/10;
   }
   return  x;
}
void main()
{
    
      unsigned long  n=-1;
   while(n>99999999||n<0)
  {
    
     printf("Please input(0<n<100000000): ");  scanf("%ld",&n);  }
  printf("\nThe result is: %ld\n",fun(n));
}

Guess you like

Origin blog.csdn.net/weixin_44856544/article/details/114908443