全部问题 > 当前问题

这个填空题不明白,

虽然这道填空题的填空处搞明白了,但是还是觉得主函数中我标颜色的两句不知道为何要这样写?


#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)  ========》这个while循环是用来干嘛的?不不循环不行吗?

  { printf("Please input(0<n<100000000): ");  scanf("%ld",&n);  }

  printf("\nThe result is: %ld\n",fun(n));

}


清华小生 2016-9-17 15:44:36

共 1 个回答

最佳答案

qqq 2016-9-17 20:49:26

i赋初值是为了进入下面的while循环,而while循环是为了防止你输入不符合条件的n值

问题来自: 填空题真题