Average and median of entered number list using C

#include<stdio.h>

void main()
{
int i,j,n,flag;
double a[30],temp,sumx=0,avg;
printf("enter the value of n \n");
scanf("%d",&n);
printf("enter the numbers\n");
for(i=0;i<n;i++)
scanf("%lf",a[i]);
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
sumx+=a[i];
avg=sumx/n;
if(n%2==0)
flag=1;
else
flag=0;
if(flag)
printf("medians are %lf and %lf\n",a[(n/2)-1],a[n/2]);
else
printf("median is %lf\n",a[(n/2)]);
printf("average is %lf \n",avg);
getchar();
}
Average and median of entered number list using C

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top

Pin It on Pinterest