define _CRT_SECURE_NO_WARNI NGS include malloc include stdio include s

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
#define _CRT_SECURE_NO_WARNINGS
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
void min_max(double* arr, int str, int stl, int* min, int* max, int * sum)
{
*min = *(arr + stl * str + 0);
*max = *(arr + stl * str + 0);
*sum = 0;
for (int i = 0; i < stl-3; i++)
{
if (*min > *(arr + stl * str + i))
{
*min = *(arr + stl * str + i);
}
if (*max < * (arr + stl * str + i))
{
*max = *(arr + stl * str + i);
}
*sum += *(arr + stl * str + i);
}
}
int main(int argc, char* argv[])
{
setlocale(LC_ALL, "ru");
FILE* file = fopen("in.txt", "r" );
int N, M;
char c = '1';
M = N = 0;
while (!feof(file))
{
do
{
double tmp;
if (fscanf(file, "%lf", &tmp));
{
N++;
}
c = fgetc(file);
if (c == '\n')
{
M++;
}
} while (c == ' ');
}
int min, max, sum;
double* arr;
M++;
N/=M;
N += 3;
arr = calloc(N * M, sizeof(double));
rewind(file);
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N - 3 ; j++)
{
fscanf(file, "%lf", (arr + i * N + j));
}
}
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
printf("%3.3lf ", *(arr + i * N + j));
}
printf("\n");
}
for (int i = 0; i < M; i++)
{
min_max(arr, i, N , &min, &max, &sum);
*(arr + i * N + (N - 3)) = sum;
*(arr + i * N + (N - 2)) = min;
*(arr + i * N + (N - 1)) = max;
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
printf("%3.3lf ", *(arr + i * N + j));
}
printf("\n");
}
}
fclose(file);
remove("in.txt");
file = fopen("in.txt", "w");
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
if (j == N - 1)
{
fprintf(file, "%3.3lf", *(arr + i * N + j));
}
else
{
fprintf(file, "%3.3lf ", *(arr + i * N + j));
}
}
fprintf(file, "\n");
}
fclose(file);
free(arr);
return 0;
}