Median of sorted array by R4R Team

Example-
Array is: [1,9,4,3,6]
Median is: 4
-Here we just try to find the middle number of the array.

program-

#include< stdio.h>
int main()
{
int a[20],n,i,median;
printf("Enter number of elements in array\n");
scanf("%d",&n);
printf("Enter %d number in array",n);
//input in array
for(i=0;i< n;i++)
scanf("%d",&a[i]);
median=n/2;
printf("Median is %d",a[median]);
}


output-

Enter number of elements in array
5
Enter 5 number in array
1 2 3 4 5
Median is 3

-In this program, we take an input in array, then median element are found by the a[n/2].




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!