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

C Programming: Please provide explanation as you work out the code, or comment.

ID: 3597271 • Letter: C

Question

C Programming: Please provide explanation as you work out the code, or comment. I want to understand why the code is being used, not just view the code. This needs to be in C. I have include the functions we are using for the mean, variance, min, max, and median of input data.

Thank you very much.


// calculates the mean of the elements of an array
float get_average(const float array[], int size)
{
int i;
float sum = 0.0;

for (i = 0; i < size; i++)
sum += array[i];

sum /= size;

return sum;
}

// calculates the variance of the emelemts of an array
// this function calls the get_average to get the mean
float get_variance(const float array[], int size)
{
int i;
float sum = 0.0;

float mean = get_average(array, size);


for (i = 0; i < size; i++)
sum += array[i] * array[i];

sum = sum/size - mean*mean;

return sum;

}

// gets the median of an array after it sorts it
float get_median(const float array[], int size)
{
int i;
float temp_array[size]; // temp array tp be manipulated
float median;

// copy oroginal array to the temp array
for (i = 0; i < size; i++)
temp_array[i] = array[i];

sort(temp_array, size, 'a');

if (size % 2 == 0)
median = (temp_array[size/2] + temp_array[size/2-1])/2.0;
else
median = temp_array[size/2];

return median;
}

// finds the maximum value of the elements of an array
int get_max(const float array[], int size)
{
int i;
float max = array[0];

for (i = 0; i < size; i++)
if (array[i] >= max)
max = array[i];

return max;
}


// finds the minimum value of the elements of an array
int get_min(const float array[], int size)
{
int i;
float min = array[0];

for (i = 0; i < size; i++)
if (array[i] <= min)
min = array[i];

return min;

}

Algorithms Data: Stock prices input in several ways Result: mean, variance, min, max, and median of input data i begin 2if the user enters nothing on the command line then This is the modified Project 3 greet and read the data; 4 end 5 else if they enter one value then if it's a single number then Implement the mdified Project 3 logic in reading the data; end else assume the delimiter is a ','; count the number of entries; allocate array; parse the input string and store the values into arrays; 10 12 13 14 15 end 16else 17 18 19end end get the number of entries; put each entry into an array;

Explanation / Answer

#include <stdio.h>

int main(int argc, char **argv) //command line argument

{

int i,a[100];

//user has enter nothing in command prompt

if(argc<1)

{

printf("please enter the values"); //prompt the user to enter value

}

//user has enter only one argument

else if(argc=1)

{

//user enter is a numeric value

if(isdigit(argv[0])) //check whether the argument is numeric

{

proj3(); //calls the function proj3

}

//user enter more than one value seperated by ','

else if(argv[1]=",")

{

for (int i = 0; i < argc; i+2) //allocate the values into array

{

a[i]=argv[i];

}

}

}

//user enter values continuesly

else

{

for (int i = 0; i < argc; ++i) //allocate the values into array

{

a[i]=argv[i];

}

}

}