啊哈磊_编程从这里起步

标题: 运行成功,但没反应=.=''''' [打印本页]

作者: tom075395    时间: 2013-12-2 10:03
标题: 运行成功,但没反应=.='''''
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=0,b=0;
while(a<5,b<5)
{
printf("*");
a=a+1,b=b+1;
while(b==5)
{
printf("\n");
a=0;
}
}
system("pause");
return 0;
}

运行成功,但没反应=.=''运行成功,但没反应=.=''运行成功,但没反应=.=''
只弹出那个视窗

#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=0,b=0;
while(a<5,b<5)
{
printf("*");
a=a+1,b=b+1;
while(b==5)
{
printf("\n");
a=0;
}
}
system("pause");
return 0;
}

运行成功,但没反应=.=''运行成功,但没反应=.=''运行成功,但没反应=.=''
只弹出那个视窗


作者: 4399APPLE    时间: 2013-12-2 11:02
出问题了:刚开始的时候你马上用鼠标抓住那个滚动条,拖到最上边,你会发现它的确输出了5个“*”
但是当b的值为5时,就进入了无限循环,一直换行,又没有使b的值变化的语句
所以就是一直换行。。。
我猜你想要的正确代码如下:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main()
  4. {
  5. int a=0,b=0;
  6. while(a<5)
  7. {
  8. printf("*");
  9. a=a+1,b=b+1;

  10. if(b==5)
  11. {
  12. printf("\n");
  13. a=0;
  14. }
  15. }
  16. system("pause");
  17. return 0;
  18. }
复制代码
第2个while循环要改为if,第1个while循环中的b<5似乎也没什么作用
作者: tom075395    时间: 2013-12-4 11:29
4399APPLE 发表于 2013-12-2 11:02
出问题了:刚开始的时候你马上用鼠标抓住那个滚动条,拖到最上边,你会发现它的确输出了5个“*”
但是当b的 ...

if...........
b+=1
b>5,b!=0
作者: 4399APPLE    时间: 2013-12-4 13:05
tom075395 发表于 2013-12-4 11:29
if...........
b+=1
b>5,b!=0

什么意思                    
作者: 不能超过7个字呃    时间: 2014-2-24 00:06
打酱油。。。




欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/) Powered by Discuz! X3.2