How to calculate median of an array Use any programming language you would like to use

The Eduladder is a community of students, teachers, and programmers just interested to make you pass any exams. So we solve previous year question papers for you.
In eduladder you can Ask,Answer,Listen,Earn and Download Questions and Question papers.
Watch related videos of your favorite subject.
Connect with students from different parts of the world.
Apply or Post Jobs, Courses ,Internships and Volunteering opportunity. For FREE
See Our team
Wondering how we keep quality?
Got unsolved questions? Ask Questions

Model-Question-Paper--PROGRAMMING-IN-C-AND-DATA-STRUCTURES--14PCD1314PCD23-->View question

Asked On2017-06-07 08:35:33 by:scribed

Taged users:

Be first to like this question

Be first to dislike this question
Talk about this  Delete  Like  Dislike
View all qusetions

You might like this video:programming language
Watch more here

Watch more videos from this user Here

Learn how to upload a video and start earning here

If n is odd then Median (M) = value of ((n + 1)/2)th item term. Try sorting the array first. Then after it's sorted, if the array has an even amount of elements the mean of the middle two is the median, if it has a odd number, the middle element is the median

// Median and mean

void main() 
int x[100],n,i;
float mean(int,int[]);
float median(int,int[]);

float mean(int m, int a[]) {
    int sum=0, i;
    for(i=0; i<m; i++)

float median(int n, int x[]) {
    float temp;
    int i, j;
    // the following two loops sort the array x in ascending order
    for(i=0; i<n-1; i++) {
        for(j=i+1; j<n; j++) {
            if(x[j] < x[i]) {
                // swap elements
                temp = x[i];
                x[i] = x[j];
                x[j] = temp;

    if(n%2==0) {
        // if there is an even number of elements, return mean of the two elements in the middle
        return((x[n/2] + x[n/2 - 1]) / 2.0);
    } else {
        // else return the element in the middle
        return x[n/2];

Answerd on:2017-06-13 Answerd By:prajwalamv

Be first to like this answer

Be first to dislike this answer
Talk about this  Delete  Like  Dislike

You might like this video:Delivering bad news to patients in a good manner
Watch more here

Watch more videos from this user Here

Learn how to upload a video and start earning here

Lets together make the web is a better place

We made eduladder by keeping the ideology of building a supermarket of all the educational material available under one roof. We are doing it with the help of individual contributors like you, interns and employees. So the resources you are looking for can be easily available and accessible also with the freedom of remix reuse and reshare our content under the terms of creative commons license with attribution required close.

You can also contribute to our vision of "Helping student to pass any exams" with these.
Answer a question: You can answer the questions not yet answered in eduladder.How to answer a question
Career: Work or do your internship with us.Work with us
Create a video: You can teach anything and everything each video should be less than five minutes should cover the idea less than five min.How to upload a video on eduladder