Sunday, November 28, 2010

Write the program to calculate the Median of a given array

#include

main()

{

int i,j,n;

float median,t;

printf("Enter the size of the array\n");

scanf("%d",&n);

float a[n];

printf("Enter the values\n");

for(i=0;i
scanf("%f",&a[i]);

for(i=0;i
{

for(j=1;j
{

if(a[j-1]
{

t=a[j-1];

a[j-1]=a[j];

a[j]=t;

}

else

continue;

}

}

if(n%2==0)

median=(a[n/2]+a[n/2+1])/2;

else

median=a[n/2+1];

for(i=0;i
printf(" %.2f",a[i]);

printf("\nMedian is =%f\n",median);

getch();

}