Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double getMedian();
- int a[] = {3, 4, 5, 1, 6};
- double getMedian(int array[], int size) {
- return (size % 2 ? array[size / 2] : (array[size / 2 - 1] + array[size / 2]) / 2);
- }
- void sort(int array[], int size) {
- for(int i=0;i<size;i++)
- {
- for(int j=0;j<size;j++)
- {
- if(a[i]>a[j])
- {
- int temp=a[i];
- a[i]=a[j];
- a[j]=temp;
- }
- }
- }
- }
- int main() {
- int size = sizeof(a)/sizeof(int);
- sort(a, size);
- cout << getMedian(a, size) << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement