Hey guys,
I'm having a little trouble putting this together. I believe I have the formula correct on the bottom, but I can't seem get the program to work. The idea is that it needs to be able to run like this:
./sdev < input.file
I have a simple understanding of how to up it together in concept, but not entirely sure on how to actually put it together in C.
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> void statistics (const int *arr, int n, float *average, float *std_dev) int main () { while(fscanf(input, "%d", &i) !=EOF); { n++; } int sum = 0; int sum_squares = 0; float variance; float average; float std_dev; int i; for (i = 0; i < n; i++) { sum += aar[i]; sum_squares += arr[i]*arr[i]; } *average = sum / n; variance = sum_squares / n - (*average) * (*average); *std_dev = sqrt (variance); printf("The average is %d\n" , *average); printf("The standard deviation is %d\n" , *std_dev); return(0); }
I've found a few example of standard deviations in C online, but many of those are done with a fixed number of array. I was hoping someone can walk me through his.