main()
{ int x=3;
while(x%3!=2)
x+=2;
printf("x=%d\n",x);
while(x%5!=4)
x+=6;
printf("x=%d\n",x);
while(x%6!=5)
x+=30;
printf("x=%d\n",x);
while(x%7!=0)
x+=30;
printf("x=%d\n",x);
}
运行得5 29 29 119 为什么等于29?后面的我懂了,就是前面的不知啊.
void main()
{ int x=3;
while(x%3!=2)
x+=2;
printf("x=%d\n",x);
while(x%5!=4) /*(x%5!=4)为真,执行x+=6直到不满足时,退出循环时*/
x+=6;
printf("x=%d\n",x);
while(x%6!=5) /*x=29,(x%6!=5)为真,执行x+=30直到不满足时,退出循环时,通过判断,x=29,不管加多少个30,都不能满足条件,所以退出*/
x+=30;
printf("x=%d\n",x);
while(x%7!=0) /*(x%7!=0)为真,执行x+=30直到不满足时,退出循环时*/
x+=30;
printf("x=%d\n",x);
}
楼上的错了
main()
{ int x=3;
while(x%3!=2)
x+=2;
printf("x=%d\n",x);
while(x%5!=4)/*此句等价于if(x%5!=4) (x%5!=4)==1( 布尔值)执行 else (x%5!=4)==0(布尔值) 跳过*/
x+=6;
printf("x=%d\n",x);
while(x%6!=5) /*此句等价于if(x%6!=5) (x%6!=5)==1( 布尔值)执行 else (x%6!=5)==0(布尔值) 跳过*/
x+=30;
printf("x=%d\n",x);
while(x%7!=0) /*此句等价于if(x%7!=0) (x%7!=0)==1( 布尔值)执行 else (x%7!=0)==0(布尔值) 跳过*/
x+=30;
printf("x=%d\n",x);
}
[此贴子已经被作者于2005-12-30 19:23:42编辑过]