C++问题:输入8个数字 按照从大到小的顺序排序 然后输出

来源:百度知道 编辑:UC知道 时间:2024/05/04 17:26:29
#include<iostream>
#include<string>
using std::string;
using std::cin;
using std::cout;
using std::endl;
int main(){
int A[8];
int* pA[8];
int count=1;
do{
cout<<"ÊäÈëµÚ"<<count<<"¸öÔªËØ";
cin>>A[count++];
}while(count<8);
pA[8]=&A[8];
for(int i=0;i<7;i++)
{
for(int k=1;k<7;k++)
{
if(A[i]<=A[i+k])
{
int* ptemp=pA[i];
pA[i]=pA[i+k];
pA[i+k]=ptemp;
}
}
}
cout<<" "<<endl;
for(int a=0;a<7;a++)
{
cout<<A[a]<<endl;
}
return 0;
}
程序是输入8个数字 按照从大到小的顺序排序 然后输出,

#include <iostream>
using namespace std;
int main()
{
int nArrow[8]={0};
for(int i=0; i<8; i++)
{
cout<<"请输入第"<<i+1<<"个数字:"<<endl;
cin>>nArrow[i];
}

for(int j=0; j<8; j++)
{
int temp=nArrow[j];
for(int k=j+1; k<8; k++)
{
if(temp<nArrow[k])
{
nArrow[j]=nArrow[k];
nArrow[k]=temp;
temp=nArrow[j];
}
}
}

cout<<"所输入数字从大到小排列为:"<<endl;
for(int m=0; m<8; m++)
{
cout<<nArrow[m]<<" ";
}
cout<<endl;
return 0;
}