求C++程序:任意从键盘输入10个整数,按从小到大的顺序排序,并输出结果.
人气:451 ℃ 时间:2020-05-06 09:18:57
解答
#include <iostream>
using namespace std;
int main()
{
int a[10],i,j,k,temp;
cout<<"请输入10个数"<<endl;
for(i=0;i<10;i++)
cin>>a[i];
for(i=0;i<9;i++)
{
k=i;
for(j=i+1;j<10;j++)
if(a[k]>a[j]) k=j;
if(k!=i)
{
temp=a[i];
a[i]=a[k];
a[k]=temp;
}
}
for(i=0;i<10;i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;
}

推荐
猜你喜欢
- 若(m+2)的平方+(n-3)的四次方=0,则代数式3(n-n)分之2的值为多少
- 金属元素最外层电子数一般()4个,容易失去电子而带()电,带正电的原子或原子团叫做()离子,而非金属最外层电子数一般()4个,容易得到电子而带()点,带负电的原子或原子团叫做()离子
- 离心微生物细胞需要多大的RCF
- one sentence have two side
- 电能表盘上标有“3000r/kw.h”字样若该电能表的转盘转300转用了半小时(转速不变),4h将消耗电能多少Kw·h
- 在三角形ABC中,AB=BC(是BC),角A=70度,O为三角形ABC内一点,且角OBC=角OCA,求角BOC的度数.
- that will be a good way to keep both teachers and students_____.
- the nurse told the patient the good news until she entered the room.咋改错