EzicMan

z1

Sep 5th, 2019
103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(void){
  5. FILE *test;
  6. long long a;
  7. int code;
  8. long long sum1 = 0, sum2 = 0;
  9. long double ans;
  10. int count = 0;
  11. if((test = fopen("test.txt","r")) == NULL){
  12. printf("Can't open file!\n");
  13. getchar();
  14. return 1;
  15. }
  16. while((code=fscanf(test,"%lld",&a)) == 1){
  17. sum1 += a*a;
  18. sum2 += a;
  19. count++;
  20. }
  21. if(code != EOF){
  22. printf("Can't read data from file!");
  23. getchar();
  24. fclose(test);
  25. return 2;
  26. }
  27. if(count == 0){
  28. printf("File is empty!");
  29. getchar();
  30. fclose(test);
  31. return 2;
  32. }
  33. ans = (double)(sum1*count - sum2*sum2)/(count*count);
  34. printf("%Lf\n",ans);
  35. fclose(test);
  36. return 0;
  37. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×