两个值按大小交换没成功
这是一个随便输入10个数 然后升序输出的程序我想问下为啥没交换? 怎么改? 谢谢
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int i,j,temp,a[11];
cout<<"enter data:"<<endl;
for(i=1;i<=10;i++)
{
cout<<"a["<<i<<"]=";
cin>>a[i];
}
cout<<endl<<"The original numbers:"<<endl;
for(i=1;i<=10;i++)
cout<<a[i]<<" ";
cout<<endl;
for(i=1;i<=9;i++)
{
for(j=i+1;j<=10;j++)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[i]=temp;
}
}
cout<<endl<<"The sorted numbers:"<<endl;
for(i=1;i<=10;i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;
}