Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MAX 100
- int main(){
- int sum = 0;
- int element[MAX];
- int i = 0;
- char filename[80];
- printf("Statistics Calculator\n");
- printf("=====================\n");
- printf("Enter the name of the data file: "); scanf("%s",filename);
- FILE * f;
- f = fopen(filename, "r");
- if (f == NULL){
- printf("Cannot open file\n");
- return;
- }
- while (!feof(f)){
- fscanf(f,"%d",&element[sum++]);
- }
- fclose(f);
- float m = 0.0;
- float s = 0.0;
- for(i=0; i<sum; i++){
- m += element[i];
- s += element[i]*element[i];
- }
- m/=sum;
- float res = s/sum - m*m;
- printf("The number of data values read from this file was %d\n", sum);
- printf("Their statistical mean is %f\n", m);
- printf("Their standard deviation is %f\n", res);
- }
Advertisement
Add Comment
Please, Sign In to add comment