开心每一天1111
12345678910111213141516171819202122232425#include "stdafx.h"#include <iostream>using namespace std; void Middle(int elem[],int n) //先对数组冒泡排序,输出中间值{ for (int i=1; i<n; i++) { for (int j=0; j<n-1; j++) { if (elem[j]>elem[j+1]) { swap(elem[j],elem[j+1]); } } } cout<<"中间值:"<<elem[(n+1)/2]<<endl; //如果你要找中间值,应该输出elem[n/2]}int _tmain(int argc, _TCHAR* argv[]){ int elem[5] = {2, 4, 1, 3, 5}; Middle(elem, 5); return 0;}1