Array Median [ZOHO]
C CODE:
#include<stdio.h>
#include <stdlib.h>
int main()
{
int i,j,k,n,t=0,e=100000,u=0,t3;
float t44,t1;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d ",&a[i]);
}
for(i=0;i<n;i++)
{
t=t+a[i];
}
t1=(float)t/n;
//printf("%.2f",t1);
float c[n],w2;
for(i=0;i<n;i++)
{
w2=(float)a[i];
c[i]=abs(t1-w2);
//printf("%d ",c[i]);
}
for(i=0;i<n;i++)
{
if(e>c[i])
{
e=c[i];
u=i;
}
}
printf("\n %d",a[u]);
}
Comments
Post a Comment