計算機 c++ 找中值算法
1 回答
開心每一天1111
TA貢獻1836條經驗 獲得超13個贊
| 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 |
- 1 回答
- 0 關注
- 604 瀏覽
添加回答
舉報
0/150
提交
取消
