Need program in C. Write a program that creates a 100 element array of random nu
ID: 3766618 • Letter: N
Question
Need program in C.
Write a program that creates a 100 element array of random numbers from 0 to 20. Manually add 1000 to any one element. Manually subtract 800 from any one element other than the one to which you just added 1000. These two elements serve as outliers so that the data is at least somewhat more realistic. Then, calculate the median, the 25^th percentile, the 75^th percentile, the top and the bottom fence and the outliers as specified below. Output your random data set and the following calculated statistics for your data set. Top and Bottom Fences: The top and bottom fences mark the outer limits of the reasonably high and reasonably low data values. These values can be calculated as such: Top Fence Value = 75^th Percentile Value + 1.5^ * IQR Value Bottom Fence Value = 25^th Percentile Value - 1.5^* IQR Value Outliers: Outliers are unreasonably high or low data points. These are data point outside the bounds of the top and bottom fences. Search your data for outliers, print out how many are unreasonably high outliers, how many are unreasonably low outliers and print out their values. For this part of the problem, you will need to search your data. You can either create your own search function or use one of the search functions we discussed in class.Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
int main()
{
int array[100];
int i,j,swap;
int med,q1,q2,q3,iqr,sev_fifth,two_fifth;
int q1_index,q2_index,q3_index,IQR;
float tfv,bfv;
for(i=0;i<100;i++)
{
array[i]=rand()%50;
}
array[0]=array[0]+1000;
array[1]=array[1]-800;
printf("The Random data are ");
for(i=0;i<100;i++)
{
printf("%d%c",array[i],' ');
}
printf(" ");
//Sorting
for(i=0;i<100-1;i++)
{
for(j=0;j<100-i-1;j++)
{
if (array[j] > array[j+1])
{
swap = array[j];
array[j] = array[j+1];
array[j+1] = swap;
}
}}
q2_index=((100-1)+0)/2;
q2=array[q2_index]; //median value
printf("The median is %d ",q2);
q1=array[((q2_index-1)+0)/2];
q3=array[((q2_index+1)+99)/2];
IQR=q3-q1;
sev_fifth=array[(int)(75*100)/100];
two_fifth =array[(int)(25*100)/100];
printf("The 75th percentile is %d ",sev_fifth);
printf("The 25th percentile is %d ",two_fifth);
tfv=sev_fifth+1.5*IQR;
bfv=two_fifth-1.5*IQR;
printf("The top fence value is %f ",tfv);
printf("The bottom fence value is %f ",bfv);
printf("The outliers are ");
//searching
for(i=0;i<100;i++)
{
if(array[i]<bfv || array[i]>tfv)
{
printf("%d%c",array[i],' ');
}
}
system("PAUSE");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.