C, C++, Java, PL SQL, PHP, PL SQL, Computer Science / Applications, B.tech, MCA Projects, Talend ETL, MongoDB.
C program to find the median of n numbers
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],i,n;
float m;
printf("Enter the size of the array: ");
scanf("%d",&n);
printf("Enter the elements:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
if(n%2==0)
{
m=(a[n-1/2]+(a[n/2]))/2;
}
else
{
m=a[n/2];
}
printf("\nMedian is %f",m);
getch();
}
#include<conio.h>
void main()
{
clrscr();
int a[10],i,n;
float m;
printf("Enter the size of the array: ");
scanf("%d",&n);
printf("Enter the elements:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
if(n%2==0)
{
m=(a[n-1/2]+(a[n/2]))/2;
}
else
{
m=a[n/2];
}
printf("\nMedian is %f",m);
getch();
}
Output
Median of n numbers |
Subscribe to:
Posts (Atom)