问答题
请编写一个函数void fun(int a [],int n),其中a为数组,n为数组a的长度。函数fun()的功能是冒泡排序法将数组a元素按从小到大的顺序排列,实现数组a的升序排列。
注意:部分源程序已存在文件PROC12.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句。
文件PROC12.cpp的内容如下:
//PROC12. cpp
#include <iostream>
using namespace std;
#define MAX 100
void fun(int a[],int n);
int main ()
{
int a[MAX],n,i;
cout<<"Please enter the array size n:\n";
do {
cin>>n;
if (n>100)
cout<<"array size flowover! ReEnter a number(0-100)\n";
}while (n>100);
cout<<"Enter the array data:\n";
for (i=0; i<n; i++)
cin>>a [ii;
fun(a[],n);
for (i=0; i<n; i++)
cout<<a [i] <<" ";
cout<<end1;
return 0;
}
void fun(int a[ ],int n)
{
// * * * * * * * *
}
【参考答案】
函数fun()的定义如下: void fun(int a[ ],int n) { int F=n; while(......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)