MEDIAN Algorithm

The Median Algorithm is a statistical method that aims to find the central value of a given set of data points, which is referred to as the median. It is an incredibly useful tool in various applications, including data analysis, statistics, and probability, as it effectively represents the middle ground of a dataset, providing a more accurate picture of the typical value within the data. Unlike the mean, which calculates the average of all data points, the median remains unaffected by extreme outliers, making it a more reliable measure of central tendency in datasets with skewed distributions. To find the median, the algorithm involves sorting the dataset in ascending order and identifying the middle value. In cases where the dataset has an odd number of data points, the median is simply the value at the center of the sorted list. However, if the dataset has an even number of data points, the median is calculated as the average of the two middle values. This process allows the Median Algorithm to effectively filter out the noise caused by extreme outliers and provides a more accurate representation of the typical value within the dataset. Overall, the median algorithm is a powerful and practical tool widely used in various fields, including finance, economics, psychology, and many more.
#include<stdio.h>
//#include<conio.h>
#include<math.h>

void main()
{
	int a[10],n,i,j,temp;
	float mean,median;
	clrscr();
	printf("Enter no. for Random Numbers :");
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		a[i]=rand()%100;
	}
	printf("Random Numbers Generated are :\n");
	for(i=0;i<n;i++)
	{
		printf("\n%d",a[i]);
	}
	printf("\n");
	printf("\nSorted Data:");
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			if(a[i]<a[j])
			{
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("\n%d",a[i]);
	}

	if(n%2==0)
	{
		median=(a[n/2]+a[(n/2)-1])/2;
	}
	else
	{
		median=a[n/2];
	}
	printf("\nMedian is : %f",median);
	getch();
}

LANGUAGE:

DARK MODE: