第二个空填s>1程序应该也没错啊,为什么答案只能是s>0呢?
有生之莲 资深达人 2017-08-17 13:12:02
1921 1 0

附题目代码

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

共 1 个回答

    最佳答案

    qqq 资深元老 助教 2881天前

    可能s>1和s>0得到的结果是一样的,但逻辑上s>0更严谨,1确实不满足循环中的if条件,但不满足if条件的那么多,你为啥非要在while这儿就把1排除了呢?

您还没有登录,所以不能回复该问题
我要回复

  • 0

    点赞

  • 扫一扫分享朋友圈

    二维码

  • 分享

相关问题