Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "conio.h"
- void create_file(FILE*, float *, char*);
- void main() {
- clrscr();
- FILE *file;
- float c[40];
- char str[10];
- printf("Name of file with numbers: ");
- scanf("%s", &str);
- create_file(file, c, str);
- printf ("Write in file is success");
- getch();
- }
- void create_file(FILE *file, float *c, char *str) {
- int i = 0, j;
- int k = 0;
- float summ = 0;
- float srd;
- if ((file = fopen(str, "r")) == 0)
- printf("File is not found!");
- while (fscanf(file, "%f", &c[i]) != EOF)
- i++;
- fclose(file);
- for (j = 0; j < i; j++)
- summ += c[j];
- srd = summ/i;
- for (j = 0; j < i; j++)
- if(c[j] < srd)
- k++;
- file = fopen("file2.txt", "w");
- fprintf (file, "В файле %d чисел, величина которых меньше среднего арифметического всех чисел в Файле %s. ", k, str);
- fclose(file);
- if ((file = fopen("file2.txt", "a")) == 0)
- printf("File is not found!");
- for (j = 0; j < i; j++)
- if (c[j] < srd)
- fprintf (file, "%.4f ", c[j]);
- fclose(file);
- }
Add Comment
Please, Sign In to add comment