Advertisement
fiveriverflow

Array

Dec 15th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. //#include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.     int a[] = {3, 4, 5, 1, 6};
  9.     int size = sizeof(a)/sizeof(int);
  10.     //std::sort(&a[0], &a[size]);
  11.    
  12.     for(int i=0;i<size;i++)
  13.     {
  14.         for(int j=0;j<size;j++)
  15.         {
  16.             if(a[i]>a[j])
  17.             {
  18.                 int temp=a[i];
  19.                 a[i]=a[j];
  20.                 a[j]=temp;
  21.             }
  22.         }
  23.     }
  24.    
  25.     double median = size % 2 ? a[size / 2] : (a[size / 2 - 1] + a[size / 2]) / 2;
  26.  
  27.     cout << median << " ";
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement