there u go the working code.
Code:
#include <stdio.h>
#include <math.h>
#define SIZE 100
int temp[SIZE];
int main (void)
{
int i, sum, sum_sqr,tempi;
double mean, st_dev;
FILE *inp;
inp = fopen("C:\\Program Files\\Miracle C\\temperature.txt", "r");
if (inp == NULL)
{
printf("ERROR OPENING THAT FILE\n");
}
/* Gather and prints all the data from the file */
for (i = 0; i<SIZE; i++)
{
if(fscanf(inp, "%d", &temp[i])!=1)
break;
printf("%d\n", temp[i]);
}
/*Computes the sum and the sum of the squares of all the data*/
sum = 0;
sum_sqr = 0;
tempi=i;
for (i = 0; i < tempi; i++)
{
sum+=temp[i];
sum_sqr += temp[i] * temp[i];
}
/*Computes and prints the mean and standard deviation*/
mean = (double)sum / SIZE;
st_dev = sqrt(sum_sqr / SIZE - mean * mean);
printf("The mean is %.2f\n", mean);
printf("The standard deviation is %.2f.\n", st_dev);
fclose(inp);
getchar();
return (0);
}
/*myoutput
1
2
3
4
5
6
7
8
9
The mean is 0.45
The standard deviation is 1.34.
*/