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

Define a array (12. 3. 5. 18. 22. 7. 4.9|. using caU by reference (that is. use

ID: 3694847 • Letter: D

Question

Define a array (12. 3. 5. 18. 22. 7. 4.9|. using caU by reference (that is. use o>> pointer to pass the array to a function, which calculates the variance of this group of number In mam: Define array, pass array and print the result from the function In function Take the array and the site from main Calculate the variance of the array and return It Variance: S^2 = 1/n[(x_1 - xbar)^2 + (x_2 - xbar)^2 + ..... + (x_n - xbar)^2] = 1/n sigma_i = 1^n(x_n - xbar)^2 n is the site of the array Xbar Is the average of the array Noteyou must us# call-by-reference (the pointer) to code as required; otherwise, no credits win be given.

Explanation / Answer

#include <stdio.h>

#include <math.h>

float average(float *,int);

float var(float *a,float);

int main()

{

    float array[9]={ 12,3,5,18,22,7,4,9};

    int i,N=9;

    float *a;

    a = &array[0];

    float sum=0.0, average1=0.0f, var1=0.0;

    average1=average(a,N);

    var1=var(a,average1);

    printf("Average= %f Variance=%f ", average1, var1);

    return 0;

}

float average (float *a, int N)

{

    int i;

    float sum = 0.0;

    for (i=0;i<9;i++)

        sum = sum + *(a+i);

    return (sum / 9);

}

float var(float *a, float average1)

{

    int i;

    float sd,var1=0.0f;

    for (i=0;i<9;i++)

        var1 = var1 + pow( *(a+i) - average1, 2);

    return (var1);

}

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