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

Write a program that will use the following function prototypes: int readData(do

ID: 2248952 • Letter: W

Question

Write a program that will use the following function prototypes:

int readData(double data[]); //ask user for number of points and read in points and return number of points

double mean(double data[], int numpts);//return the mean of the values stored in data[]

int rangeCount(double data[], double low, double high, int numpts);

The function rangeCount counts the number of values in data that are higher than low and lower than high.

For example, if low=2.5 and high=7.2, all values in the passed array greater than 2.5 and less than 7.2 will be

counted.

Please use simple code.

Explanation / Answer


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int readData (double data[]);
double mean (double data[], int numpts);
int rangeCount(double data[], double low, double high, int numpts);

int main ()
{
int points, i;
double * array1, average;

points = readData(array1);
array1 = calloc(points, sizeof(double));

for (i = 0; i < points ; i++) // initialize the array
{
*(array1+i) = i+2.2;
}


printf(" The Elements of the array are :: ");
for (i = 0; i < points ; i++) // printing the array1
{
printf("%f ", *(array1+i));
}
printf(" ");

average = mean(array1, points);
printf(" Average of the elements in the array1 = %f ", average);

rangeCount(array1, 3.2, 4.7, points);

free(array1);
return 0;

}

int rangeCount(double data[], double low, double high, int numpts)
{
int i, countHigher = 0, countLower = 0;
for(i = 0 ; i < numpts; i++)
{
if((data[i]-low) > 0)
countHigher++;
if((data[i]-high) < 0)
countLower++;
}
printf(" The number of elements higher than %f are :: %d ", low, countHigher);
printf("The number of elements lower than %f are :: %d ", high, countLower);
return 0;
}

double mean (double data[], int numpts)
{
int i;
double avg, sum = 0.0;
for (i = 0; i < numpts ; i++)
{
sum = sum + data[i];
}
avg = (sum / numpts);
return avg;
}

int readData (double data[])
{
int points;
printf("Enter the number of points :: ");
scanf("%d", &points);
return points;
}

/*///////////////////// Output of Program //////////////////////////
Enter the number of points ::
4

The Elements of the array are :: 2.200000 3.200000 4.200000 5.200000


Average of the elements in the array1 = 3.700000

The number of elements higher than 3.200000 are :: 2
The number of elements lower than 4.700000 are :: 3
///////////////////////////////////////////////////////////////////////
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote