I'm trying to write a problem that calculates and prints the mean and variance of two numbers. I must create a function to calculate it and then print the results only in the main function. The way I chose was using one array of 2 positions that has the mean value in the first position and the variance value in the second position. I believe the issue is assign the values to the array, thate's waht I'm not being able to do correctly. Could someone please explain me that with some coding? If there's another way of doing that which is not using the array, it's also valid.
int * statistics (float x, float y){
double mean, var;
int i;
static int Arr[2];
mean = (x+y)/2;
var = ((x-mean)*(x-mean) + (y-mean)*(y-mean)) /2;
for (i = 0; i < 2; ++i) {
if (i=0)
{
Arr[i] = mean;
}
else
{
Arr[i] = var;
}
return Arr;
}
int main(){
int num1, num2, result;
num1 = 10;
num2 = 5;
result = statistics(num1, num2);
printf("%lf -- %lf", result[0], result[1]);
return 0;
}