C programming Write a function definition for a user-defined function that calcu
ID: 3779578 • Letter: C
Question
C programming
Write a function definition for a user-defined function that calculates the (floating-point double) mean of a specified column in a 2-D array that has NROWS rows and NCOLS columns. (NROWS and NCOLS are pre-defined symbolic constants) The parameters should be the double array and the desired column, as specified in the following function prototype: double col_mean(double x[NROWS, NCOLS], int col); Same as #3, but calculating the standard deviation rather than the mean. sigma = Squareroot 1/N sigma_i=1^N (x_i - x_avg)^2Explanation / Answer
Here is the code for the first problem:
double col_mean(double x[][NCOLS], int col)
{
double mean = 0;
for(int i = 0; i < NROWS; i++)
mean += x[i][col];
return mean / NROWS;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.