全部问题 > 当前问题

这道题有些不明白 望解答

#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;

}

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));

}


带我走@ 2016-2-26 19:22:46

共 4 个回答

嘿嘿大人 2016-2-26 21:04:08

那些地方不明白?

带我走@ 2016-2-26 21:24:44

unsigned long  n=-1;

无符号的不应该不能为负吗


带我走@ 2016-2-26 22:18:25

回复 嘿嘿大人

unsigned long  n=-1;

无符号的不应该不能为负吗


最佳答案

嘿嘿大人 2016-2-26 22:48:44

回复 带我走@:是的啊,所以这里的-1代表的就是无符号数的最大值啊,就是零的左一位,范围你可以想象为一个圈,0的前面就是范围的最大值,所以这个-1代表的就是范围的最大值

问题来自: 填空题真题