Skip to content

Instantly share code, notes, and snippets.

@cohalz
Created October 1, 2013 04:42
Show Gist options
  • Save cohalz/6773947 to your computer and use it in GitHub Desktop.
Save cohalz/6773947 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(){
int i;
float x,n;
float sum_x = 0.0;
float squared_x = 0.0;
float mean,variance;
printf("n = ");
scanf("%f", &n);
for(i=1;i<=n;i++){
printf("x = ");
scanf("%f",&x);
sum_x += x;
squared_x += x*x;
}
mean = sum_x/n;
variance = (squared_x/n)-mean*mean;
printf("mean is %f\n",mean);
printf("variance is %f\n",variance);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment