0% found this document useful (0 votes)
6 views4 pages

C Program for Data Analysis and Outlier Detection

The C code takes in a set of 27 integer values as input from the user, sorts them in ascending order, and calculates various statistical measures like median, quartiles, interquartile range, and outliers. It prints out the sorted data, extremes, median, quartiles, interquartile range, and outliers.

Uploaded by

mm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

C Program for Data Analysis and Outlier Detection

The C code takes in a set of 27 integer values as input from the user, sorts them in ascending order, and calculates various statistical measures like median, quartiles, interquartile range, and outliers. It prints out the sorted data, extremes, median, quartiles, interquartile range, and outliers.

Uploaded by

mm
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Question-7

Answer:

C Code:

#include<stdio.h>

#include<stdlib.h>

#define N 27

int main()

{ int i,j,k,temp,l,m;

float median,Q1,Q3,IQR,o1,o3;

int num[N];

printf("Enter data :\n");

for(i=0;i<N;i++)

scanf("%d",&num[i]);

for(j=0;j<N-1;j++)

for(k=j+1;k<N;k++)

if(num[j]>num[k])

temp=num[j];

num[j]=num[k];

num[k]=temp;

}
}

printf("\nSorted data:\t");

for(l=0;l<N;l++)

printf("%d\t",num[l]);

printf("\nExtremes of the data:\nMinimum : %d\tMaximum : %d",num[0],num[N-


1]);

if(N%2==0)

median=num[(N/2)-1]+num[N/2];//N starts from 1 Array Index starts from 0

median=median/2;

else

median=num[N/2];

if((N/2)%2==0)

Q1=num[(N/4)-1]+num[N/4];

Q1=Q1/2;

Q3=num[(3*N-4)/4]+num[(3*N)/4];

Q3=Q3/2;

else

{
Q1=num[N/4];

Q3=num[3*N/4];

IQR=Q3-Q1;

printf("\nMedian of data is: %f",median);

printf("\nFirst Quartile of data is: %f",Q1);

printf("\nThird Quartile of data is: %f",Q3);

printf("\nInter Quartile Range of data is: %f",IQR);

o1=Q1-(IQR*3)/2;

printf("\no1: %f",o1);

o3=Q3+(IQR*3)/2;

printf("\no3: %f\n",o3);

printf("\nList of Outliers in data: ");

for(m=0;m<(N/2)-1;m++)

if(num[m]<o1)

printf("%d\t",num[m]);

for(m=N/2;m<N;m++)

if(num[m]>o3)

printf("%d\t",num[m]);

}
}

return 0;

Output:

You might also like