Работы по программированию

This commit is contained in:
IgorVolochay
2026-07-28 09:56:54 +03:00
parent b85155ff95
commit 8602b7e845
73 changed files with 4090 additions and 0 deletions
@@ -0,0 +1,178 @@
#include <stdio.h>
#include <stdlib.h>
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();
}