Guest User

Untitled

a guest
Dec 12th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "conio.h"
  3.  
  4. void create_file(FILE*, float *, char*);
  5.  
  6. void main() {
  7. clrscr();
  8. FILE *file;
  9. float c[40];
  10. char str[10];
  11. printf("Name of file with numbers: ");
  12. scanf("%s", &str);
  13. create_file(file, c, str);
  14. printf ("Write in file is success");
  15. getch();
  16. }
  17.  
  18. void create_file(FILE *file, float *c, char *str) {
  19. int i = 0, j;
  20. int k = 0;
  21. float summ = 0;
  22. float srd;
  23. if ((file = fopen(str, "r")) == 0)
  24. printf("File is not found!");
  25. while (fscanf(file, "%f", &c[i]) != EOF)
  26. i++;
  27. fclose(file);
  28. for (j = 0; j < i; j++)
  29. summ += c[j];
  30. srd = summ/i;
  31. for (j = 0; j < i; j++)
  32. if(c[j] < srd)
  33. k++;
  34. file = fopen("file2.txt", "w");
  35. fprintf (file, "В файле %d чисел, величина которых меньше среднего арифметического всех чисел в Файле %s. ", k, str);
  36. fclose(file);
  37. if ((file = fopen("file2.txt", "a")) == 0)
  38. printf("File is not found!");
  39. for (j = 0; j < i; j++)
  40. if (c[j] < srd)
  41. fprintf (file, "%.4f ", c[j]);
  42. fclose(file);
  43. }
Add Comment
Please, Sign In to add comment