Thread: Help with program that calculates confidence interval

1. Help with program that calculates confidence interval

Hi!!
I need a little help with my program.
I have done a program that calculates mean, variance and standard devisation now I need to add the calculation for confidence interval.

The confidence interval is calculated using this equation:
mean +/- z*(standard deviation/number of samples)

I have added this to my code:
Function prototype: double conf_int(double n[ ], double stv, double z);
and
double z;
printf ("Enter the z value");
scanf ("%d", &z);

This is wher I get stuck.
I am nto sure on how to do write the code for calculationg confidence interval.
The output for example should look like this: 73.125 +/- 69.536

This is my code
Code:
```#include <stdio.h>
#include <math.h>
#define N 12

/* Function prototypes */
double mean(double n[ ]);
double variance(double n[ ], double m);
double std_dev(double v);
double conf_int(double n[ ], double stv, double z);

void main(void)
{

double mu, v, stv;
double num[N] = {87.8, 45.7, 56.7, 78.6, 49.7, 91.2, 87.6, 63.6, 59.8, 98.3, 77.2, 81.3};
double z;
printf ("Enter the z value");
scanf ("%d", &z);

/*	int ctr;

for (ctr=0; ctr<N; ctr++)
{
printf ("Please enter the next number . . . ");
scanf ("%f", &num[ctr]);
}
printf ("fdls %f", num[1]); */

mu = mean (num);
v = variance (num, mu);
stv = std_dev(v);
printf ("Mean = %.3f, Variance = %.3f\n", mu, v);
printf ("Standard Deviation = %.3f\n", stv);
printf ("Confidence Interval = %.3f\n", conf_int);

}

double mean(double n[N])
{
double sum=0.0, retVal;
int i;

for (i=0; i<N; i++)
{
sum += n[i];
}

retVal = sum/N;
return retVal;
}

double variance(double n[N], double m)
{
double ctr=0.0, retVal;
int i;

for (i=0; i<N; i++)
{
ctr += pow ((n[i] - m), 2);
}

retVal = ctr/(N-1);
return retVal;
}

double std_dev(double v)
{
double retVal;

retVal = sqrt(v);
return retVal;
}

double conf_int(double n[ ], double stv, double z);
{
?????????????????????????????```
THANK YOU

2. 1. The formula is mean +/- z*(stdev/sqrt(number of samples)).

2. Your function takes the list of numbers, the standard deviation, and z. So you'll need to calculate the mean and the number of samples. The first is easy; the second is impossible (due to the fact that C does not pass the size of the array into a function for you). However, you seem to know ahead of time that N=12, so you can run with that.

3. Once you do that, you have to calculate the mean (you have a function to do that) and z*(stdev/sqrt(12)), which involves, well, typing exactly that.

3. Code:
```double z;
scanf ("&#37;d", &z);```
do not lie to scanf... read scanf format specifiers - double should be scanned with %lf