pls provide code in basic C and not C++ or C#... It\'s very important that the c
ID: 3723706 • Letter: P
Question
pls provide code in basic C and not C++ or C#... It's very important that the code be in int main(), pls pls pls.
III.B. STATISTICS Consider two lists of n real numbers each, named X and Y X = x1, x2 , , xn The covariance of the lists, denoted cov(X, Y), is a real number that ".. provides a measure of the strength of the correlation. "§ between the two lists The covariance of X and Y is calculated as follows: cov(X, Y) = Here, T (pronounced "x-bar") is the mean of the values in the list named X, and likewise y is the mean of the values in the list named Y The mean of a list of number is defined as the sum of the numbers in the list, divided by how many numbers are in the list. So, for example, the mean of X is defined as Write a program to calculate the covariance of two lists of 4 numbers each. The program MUST incorporate the following subsections, IN THE FOLLOWING ORDER 1. Greeting Subsection: Greet the user with useful information about the program. 2. Input Subsection (a) Prompt the user to input the first list of 4 values Input the first list of 4 values, using a single scanf statement. (c) Prompt the user to input the second list of 4 values (d) Input the second list of 4 values, using a single scanf statement. 3. Calculation Subsection (a) Calculate the mean of the first list of 4 values (b) Calculate the mean of the second list of 4 values (c) Calculate the covariance of the two lists of 4 values each. 4. Output Subsection (a) Output the first list of 4 values (b) Output the second list of 4 values (c) Output the mean of the first list of 4 values (d) Output the mean of the second list of 4 values (e) Output the covariance of the two lists of 4 values each.Explanation / Answer
Here is the c code
/****************************/
/*
============================================================================
Name : Covarience.c
Author :
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
//calculate the mean
float calcMean(float* num,int size){
int i;
float sum=0;
for(i=0;i<size;i++){
sum=sum+num[i];
}
return sum/size;
}
//calculate the covarience
float calcCovar(float* x,float* y, float mx, float my,int size){
int i;
float sum=0.0;
for(i=0;i<size;i++){
sum=sum+((x[i]-mx)*(y[i]-my));
}
return sum/size;
}
int main(void) {
printf("!!!Hello Programmer!!! ");
int i;
float X[4];
float Y[4];
float mx,my;
float covar;
printf("Enter the first list of 4 ");
for(i=0;i<4;i++)
scanf("%f",&X[i]);
printf("Enter the Second list of 4 ");
for(i=0;i<4;i++)
scanf("%f",&Y[i]);
mx=calcMean(X,4);
my=calcMean(Y,4);
covar=calcCovar(X,Y,mx,my,4);
printf("First list of 4 is: ");
for(i=0;i<4;i++)
printf("%f ",X[i]);
printf(" ");
printf("second list of 4 is: ");
for(i=0;i<4;i++)
printf("%f ",Y[i]);
printf(" ");
printf("Mean of first list of 4: %f ",mx);
printf("Mean of second list of 4: %f ",my);
printf("Covarience of 2 list: %f ",covar);
return EXIT_SUCCESS;
}
/*************************/sample output
!!!Hello Programmer!!!
Enter the first list of 4 1 2 3 4
Enter the Second list of 4 5 6 7 8
First list of 4 is: 1.000000 2.000000 3.000000 4.000000
second list of 4 is: 5.000000 6.000000 7.000000 8.000000
Mean of first list of 4: 2.500000
Mean of second list of 4: 6.500000
Covarience of 2 list: 1.250000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.