labor4/main1.c
2024-11-19 15:21:40 +04:00

48 lines
969 B
C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <Windows.h>
int a[1000]; //ìàññèâ. 1000 - ìàêñèìàëüíî äîïóñòèìîå êîëè÷åñòâî ýëåìåíòîâ
int n; // Ðåàëüíîå êîëè÷åñòâî ýëåìåíòîâ â ìàññèâå
void Load() {
// Îòêðûòèå âõîäíîãî ôàéëà
FILE* fin = fopen("c:\\lab_19\\in1.txt", "rt");
if (fin == NULL) {
printf("Âõîäíîé ôàéë íå íàéäåí\n");
return;
}
// Çàãðóçêà ìàññèâà èç âõîäíîãî ôàéëà
fscanf_s(fin, "%d", &n);
for (int i = 0; i < n; i++) {
fscanf_s(fin, "%d", &a[i]);
}
// Çàêðûòèå âõîäíîãî ôàéëà
fclose(fin);
}
//commit2
void SaveResult() {
// Âû÷èñëåíèå ñðåäíåãî àðèôìåòè÷åñêîãî
float sa = 0;
float s = 0;
for (int i = 0; i < n; i++) {
s += a[i];
}
sa = s / n;
// Âûÿñíåíèå, ñêîëüêî ýëåìåíòîâ áîëüøå ñð àðèôìâðåòè÷åñêîãî
int m = 0;
for (int i = 0; i < n; i++) {
if (a[i] > sa) {
m++;
}
}
FILE* fout = fopen("c:\\lab_19\\out1.txt", "wt");
if (fout == NULL) {
printf("Âûõîäíîé ôàéë íå íàéäåí\n");
return;
}
//commit 3