0% found this document useful (0 votes)
43 views2 pages

Median

The document contains code to find the median of an array of numbers. It takes user input for the number of elements and values in the array. It then calculates the median, printing the array and result.

Uploaded by

anuj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views2 pages

Median

The document contains code to find the median of an array of numbers. It takes user input for the number of elements and values in the array. It then calculates the median, printing the array and result.

Uploaded by

anuj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM:

#include<iostream>
#include<math.h>
using namespace std;
int main(){
int a[50];
int n;
cout<<"Enter number of elements of array: ";
cin>>n;
cout<<"Enter array elements\n";
for(int i = 0; i < n; i++){
cin>>a[i]; }
int m = n / 2 ;
int result;
if(n % 2 == 0){
float w = (a[m] + a[m-1])/2.0;
result = ceil(w);
}else{
m = n / 2 ;
result = a[m];
}
cout<<"Array is: \n";
for(int i = 0; i < n; i++){
cout<<a[i]<<" ";
}
cout<<"\nMedian is "<<result<<endl;
return 0;
}

OUTPUT:

You might also like