Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main(void){
- FILE *test;
- long long a;
- int code;
- long long sum1 = 0, sum2 = 0;
- long double ans;
- int count = 0;
- if((test = fopen("test.txt","r")) == NULL){
- printf("Can't open file!\n");
- getchar();
- return 1;
- }
- while((code=fscanf(test,"%lld",&a)) == 1){
- sum1 += a*a;
- sum2 += a;
- count++;
- }
- if(code != EOF){
- printf("Can't read data from file!");
- getchar();
- fclose(test);
- return 2;
- }
- if(count == 0){
- printf("File is empty!");
- getchar();
- fclose(test);
- return 2;
- }
- ans = (double)(sum1*count - sum2*sum2)/(count*count);
- printf("%Lf\n",ans);
- fclose(test);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement