标题:冒泡法一问
取消只看楼主
chuxuechengxu
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-6-18
 问题点数:0 回复次数:1 
冒泡法一问
各位高手,帮忙看一下这个冒泡法程序,我有一点小问题:
#include<iostream>
using namespace std;
int main()
{
int a[10];
int i,j,t;
cout<<"请输入十个数:"<<endl;
for(i=0;i<10;i++)
cin>>a[i];
for(j=0;j<9;j++)
 {for(i=0;i<9-j;i++)
   if(a[i]>a[i+1])
     {
      t=a[i];
      a[i]=a[i+1];
      a[i+1]=t;
     }
 }
  cout<<"排序后的数为:"<<endl;
  for(i=0;i<=9;i++)
  cout<<' '<<a[i];
  cout<<endl;
}
问题:为什么在"cout<<"排序后的数为:"<<endl;"后面还要用for循环啊,为什么不用就不行?
搜索更多相关主题的帖子: 冒泡 
2008-07-20 12:57
chuxuechengxu
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-6-18
得分:0 
哦,知道了,谢谢啊!
2008-07-25 06:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-224556-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.092280 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved