Сделал 2 Задание

This commit is contained in:
AZEN-SGG 2024-09-23 16:27:47 +03:00
parent d32450977c
commit 8e7bf70696
5 changed files with 50 additions and 16 deletions

View file

@ -1,18 +1,38 @@
#include "count_elements.h"
int countElements(FILE * file) {
int current, count;
double detectNumber(double number, double count) {
if ((1 - number > INACCURACY) || (number - 5 > INACCURACY)) {
return 0;
}
for (double i = 1.; i < 6; i++) {
// printf("%lf ? \n", abs(number - i));
if (fabs(number - i) < INACCURACY) return (1 - (int)(fmod(count, pow(10., i)) / pow(10., i - 1))) * pow(10., i - 1);
}
return 0;
}
count = 0;
double summa(double info_count) {
int count = 0.;
if (fscanf(file, "%d", &current) != 1)
for (int i = 0; i < 5; i++) {
count += fmod(info_count, 10.);
info_count /= 10;
}
return count;
}
double countElements(FILE * file) {
double current;
double count = 100000.;
if (fscanf(file, "%lf", &current) != 1)
{
printf("File is empty!\n");
return -1;
}
do {
if (current <= 5 && current >= 1) count++;
} while (fscanf(file, "%d", &current) == 1);
count += detectNumber(current, count);
} while (fscanf(file, "%lf", &current) == 1);
return count;
}
return summa(count);
}