answersLogoWhite

0


Best Answer

import java.util.Arrays;

class Solution {

public int median(int[] A) {

int[] b = new int[A.length];

System.arraycopy(A, 0, b, 0, b.length);

Arrays.sort(b);

if (A.length % 2 == 0) {

return b[b.length / 2];

} else {

return (int) ((b[(b.length / 2) - 1] + b[b.length / 2]) / 2.0);

}

}

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to find median of n numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you figure out the median?

Finding out the median in a set of numbers is an easy process. Write out the numbers from shortest to longest, then find the number that is directly in the middle. If two numbers are in the middle, add them and divide by two to get the median.


How do you write an assembly language program to find the sum of n numbers using array?

write an assembly language program to find sum of N numbers


What is the median of 4 numbers?

To find the median of a set of numbers write them in order, then: * if there are an odd number of numbers then the median is the number in the middle * otherwise there are an even number of numbers and the median is the mean average of the two numbers in the middle. With 4 numbers there is an even number of numbers, so the median is the mean average of the 2nd and 3rd numbers when they are sorted into order. Example: Find median of {3, 9, 4, 5} Ordered → {3, 4, 5, 9} → median = mean_average(4, 5) = (4 + 5) ÷ 2 = 4.5


How do you program an ungrouped median?

find median of n observation in c program


How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers


Write c program to find median?

If you are using an array : sort using qsort() then take middle element.


Write a C plus plus to find median and mode of a number?

The median and mode of any number is the same number. The mode of 5 is 5, as is the median of 5. In other words, you need two or more numbers to determine the median and mode of those numbers.


How do you write a VBnet program to find the prime numbers between 100 to 200?

VBnet program to find the prime numbers between 100 to 200?


What happens to the median when you come up with two answer?

when you have an even amount of numbers while trying to find the median, you first find the two numbers that are at the median and then take all the numbers between them and find the median of that. if that amount of digits is also even, then you must have a decimal median.


How do find the median with 4 different numbers?

There would be no median.


What is the median in a set of numbers?

to find the median in a set of numbers you have to order them from the smallest to the largest and find the middle value e.g. 2,4,3,7,1 1,2,3,4,7 the median is 3


How do you find the median when there are 6 numbers?

you find the two numbers in the middle and add them. divide the sum by two. that's the median.