问答题

给定一个函数,其函数功能为:使10个整数按由小到大的顺序排列。在主函数中输入10个数,并输出结果。使用VC6打开考生文件夹下的工程RevProj5。此工程包含一个源程序文件RevMain5.cpp,该程序实现上述功能。但此程序运行有问题。请找出错误的地方,改正后将此程序调试正确。
注意:不得删行或增行,也不得更改程序结构。
文件RevMain5.cpp中的程序清单如下:
//RevMain5.cpp
#include<iostream>
#include<iomanip>
using namespace std;
int main()

void sort(int array[],int n);
int data[10],*p,i;
cout<<"Input 10 numbers\n";
for (i=0; i<10; i++)
cin>>data [i];
cout<<"the origined array is:";
for (p=data;p<data+10;p++)

if((p-&data[0]) %5==0)
cout<<" \n";
cout<<setw (5) <<*p;

sort (data, 10);
cout<<"\n the present array is:";
for(p=data;p〈data+10;p++)

if((p-&data[0])%5==0) cout<<"\n";
cout<<setw (5)<<*p;


void sort(int array[],int n)

/* * * * * * * * *found * * * * * * * * * */
for(p1=array;p1<array+(n-1) ;p1++)

for (p2=p1+1 ;p2<array+n;p2++)

if (*p1>*p2)

/* * * * * * * * *found * * * * * * * * * */
temp=*p1; *p1=*p2; *p2=*p1;



【参考答案】

修改后的函数sort为:
void sort(int array[],int n)
{
i......

(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)