#include #include int t19_a() { FILE *fp; int num, count_positive = 0, count_negative = 0; int sum_positive = 0, sum_negative = 0; float avg_positive = 0.0, avg_negative = 0.0; fp = fopen("netext_a.bin", "rb"); // Открытие бинарного файла для чтения if (fp == NULL) { printf("Ошибка открытия файла!\n"); return 1; } while (fread(&num, sizeof(char), 1, fp) == 1) { // Чтение по 1 целому числу if (num > 0) { count_positive++; sum_positive += num; } else if (num < 0) { count_negative++; sum_negative += num; } } fclose(fp); // Закрытие файла if (count_positive > 0) { avg_positive = (float)sum_positive / count_positive; } if (count_negative > 0) { avg_negative = (float)sum_negative / count_negative; } printf("Number of positive numbers: %d\n", count_positive); printf("Number of negative numbers: %d\n", count_negative); printf("Sum of positive numbers: %d\n", sum_positive); printf("Sum of negative numbers: %d\n", sum_negative); printf("Arithmetic mean of positive numbers: %.2f\n", avg_positive); printf("Arithmetic mean of negative numbers: %.2f\n", avg_negative); return 0; } int t19_b() { FILE *fp; int num, count_positive = 0, count_negative = 0; int sum_positive = 0, sum_negative = 0; float avg_positive = 0.0, avg_negative = 0.0; fp = fopen("netext_b.bin", "rb"); // Открытие бинарного файла для чтения if (fp == NULL) { printf("Ошибка открытия файла!\n"); return 1; } while (fread(&num, sizeof(short), 1, fp) == 1) { // Чтение по 1 целому числу if (num > 0) { count_positive++; sum_positive += num; } else if (num < 0) { count_negative++; sum_negative += num; } } fclose(fp); // Закрытие файла if (count_positive > 0) { avg_positive = (float)sum_positive / count_positive; } if (count_negative > 0) { avg_negative = (float)sum_negative / count_negative; } printf("Number of positive numbers: %d\n", count_positive); printf("Number of negative numbers: %d\n", count_negative); printf("Sum of positive numbers: %d\n", sum_positive); printf("Sum of negative numbers: %d\n", sum_negative); printf("Arithmetic mean of positive numbers: %.2f\n", avg_positive); printf("Arithmetic mean of negative numbers: %.2f\n", avg_negative); return 0; } int t19_v() { FILE *fp; int num, count_positive = 0, count_negative = 0; int sum_positive = 0, sum_negative = 0; float avg_positive = 0.0, avg_negative = 0.0; fp = fopen("netext_v.bin", "rb"); // Открытие бинарного файла для чтения if (fp == NULL) { printf("Ошибка открытия файла!\n"); return 1; } while (fread(&num, sizeof(int), 1, fp) == 1) { // Чтение по 1 целому числу if (num > 0) { count_positive++; sum_positive += num; } else if (num < 0) { count_negative++; sum_negative += num; } } fclose(fp); // Закрытие файла if (count_positive > 0) { avg_positive = (float)sum_positive / count_positive; } if (count_negative > 0) { avg_negative = (float)sum_negative / count_negative; } printf("Number of positive numbers: %d\n", count_positive); printf("Number of negative numbers: %d\n", count_negative); printf("Sum of positive numbers: %d\n", sum_positive); printf("Sum of negative numbers: %d\n", sum_negative); printf("Arithmetic mean of positive numbers: %.2f\n", avg_positive); printf("Arithmetic mean of negative numbers: %.2f\n", avg_negative); return 0; } int t20() { FILE *fp; int num, count_positive = 0, count_negative = 0; int sum_positive = 0, sum_negative = 0; float avg_positive = 0.0, avg_negative = 0.0; fp = fopen("netext2.bin", "rb"); // Открытие бинарного файла для чтения if (fp == NULL) { printf("Ошибка открытия файла!\n"); return 1; } while (fread(&num, sizeof(char), 1, fp) == 1) { // Чтение по 1 целому числу if (num > 0) { count_positive++; sum_positive += num; } else if (num < 0) { count_negative++; sum_negative += num; } } fclose(fp); // Закрытие файла if (count_positive > 0) { avg_positive = (float)sum_positive / count_positive; } if (count_negative > 0) { avg_negative = (float)sum_negative / count_negative; } printf("Number of positive numbers: %d\n", count_positive); printf("Number of negative numbers: %d\n", count_negative); printf("Sum of positive numbers: %d\n", sum_positive); printf("Sum of negative numbers: %d\n", sum_negative); printf("Arithmetic mean of positive numbers: %.2f\n", avg_positive); printf("Arithmetic mean of negative numbers: %.2f\n", avg_negative); return 0; } void main() { printf("a\n"); t19_a(); printf("b\n"); t19_b(); printf("v\n"); t19_v(); printf("20\n"); t20(); }