Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NEED IT QUICK PLEASE Write a C program that calculates the mean, median and mode

ID: 3587515 • Letter: N

Question

NEED IT QUICK PLEASE

Write a C program that calculates the mean, median and mode of a given array in the following manner:

i) Write three functions mean (), median () and mode () that calculates the mean, median and mode of an array.

ii) Using these functions write a program that calculates all the three above mentioned values for two different arrays A and B where A is an array that contains the number of hours spent by a person each day for playing video games and B is an array that contains the number of hours spent by a person each day for his studies.

iii) Based on the above mentioned values that you calculate using these functions compare the values obtained from both the arrays. If all the three values of array A is greater than array B print statement that warns the person to study. If all the three values of array B is greater than array A print statement that praises him for his studies. If all the three values are equal print statement that tells him he is well balanced. If any other issues, print "Sorry can't come to an outcome". Example: Let array A be: 4 5 5 2 8 9 Let array B be: 2 3 1 4 8 4 Mean of A is: 5.5 Median of A is: (5+2)/2=3.5 Mode of A is: 5 Mean of B is: 3.6 Median of B is: (1+4)/2=2.5 Mode of B is: 4 Here Mean, Median and Mode of A is larger than B. Therefore we print "You're playing more video games you have to spent more time studying". In case if Mean, Median and Mode of A is lesser than B then you print "Good, you're spending considerable time in studying".(input from the user).

Explanation / Answer

for mean:-


float mean(int x, int b[]) {
int sum=0, i;
for(i=0; i<x; i++)
sum+=b[i];
return((float)sum/x);
}

for median:-

float mediam(int m, imt y[]) {
float temp;
int i, j;
// the two loops sort the array y in ascending order
for(i=0; i<m-1; i++) {
for(j=i+1; j<m; j++) {
if(y[j] < y[i]) {
// swaping elements
temp = y[i];
y[i] = y[j];
y[j] = temp;
}
}
}

if(m%2==0) {
// if there is an even number of elements, return mean of the two elements in the middle
return((y[m/2] + y[m/2 - 1]) / 2.0);
} else {
// else return the element in the middle
return y[m/2];
}

for mode:-

int mode(int t[],int n) {
int mValue = 0, mCount = 0, i, j;

for (i = 0; i < n; ++i) {
int count = 0;
  
for (j = 0; j < n; ++j) {
if (t[j] == t[i])
++count;
}
  
if (count > mCount) {
mCount = count;
mValue = t[i];
}
}

return mValue;
}