From 5dbf4901b8a5bba478421174b92eae8aafe6d549 Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Fri, 27 Sep 2024 09:30:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=2010?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 10Ex/count_between.c | 30 ++++++++++++++++++++++++++++++ 10Ex/count_between.h | 12 ++++++++++++ 10Ex/input.txt | 1 + 10Ex/main.c | 34 ++-------------------------------- 10Ex/makefile | 11 +++++++++++ Second/count_elements.c | 2 +- Second/input.txt | 17 +---------------- 7 files changed, 58 insertions(+), 49 deletions(-) create mode 100644 10Ex/count_between.c create mode 100644 10Ex/count_between.h create mode 100644 10Ex/input.txt create mode 100644 10Ex/makefile diff --git a/10Ex/count_between.c b/10Ex/count_between.c new file mode 100644 index 0000000..dac6d4c --- /dev/null +++ b/10Ex/count_between.c @@ -0,0 +1,30 @@ +#include "count_between.h" + +double fmax(double a, double b) { + if ((a - b) > eps) return a; + return b; +} + +double fmin(double a, double b) { + if ((a - b) > eps) return b; + return a; +} + +int countBetween(FILE * file) { + double first, second, current; + int count = 0; + + if ((fscanf(file, "%lf", &first) != 1) || (fscanf(file, "%lf", &second) != 1)) { + printf("There is NO 2 variables\n"); + return 1; + } + + current = fmax(first, second); + second = fmin(first, second); + first = current; + + while (fscanf(file, "%lf", ¤t) == 1) { + if (((current - second) > eps) && ((first - current) > eps)) count++; + } + return count; +} diff --git a/10Ex/count_between.h b/10Ex/count_between.h new file mode 100644 index 0000000..b4a817b --- /dev/null +++ b/10Ex/count_between.h @@ -0,0 +1,12 @@ +#ifndef COUNT_BETWEEN +#define COUNT_BETWEEN + +#include + +#define eps 1.e-6 + +double fmax(double a, double b); +double fmin(double a, double b); +int countBetween(FILE * file); + +#endif // COUNT_BETWEEN diff --git a/10Ex/input.txt b/10Ex/input.txt new file mode 100644 index 0000000..863cf0e --- /dev/null +++ b/10Ex/input.txt @@ -0,0 +1 @@ +1 5 2 3 4 1.1 10 5.5 0.5 0 -1 -2 \ No newline at end of file diff --git a/10Ex/main.c b/10Ex/main.c index 2a4841a..a7398ef 100644 --- a/10Ex/main.c +++ b/10Ex/main.c @@ -1,38 +1,8 @@ #include #include "tools.h" +#include "count_between.h" -#define eps = 1.e-10 - -double fmax(double a, double b) { - if ((a - b) > eps) return a; - return b; -} - -double fmin(double a, double b) { - if ((a - b) > eps) return b; - return a; -} - -int countBetween(FILE * file); - -int countBetween(FILE * file) { - double first, second, current; - int count = 0; - - if ((fscanf(file, "%lf", &first) != 1) || (fscanf(file, "%lf", &second) != 1) { - printf("There is NO 2 variables\n"); - return 1 - } - - current = fmax(first, second); - second = fmin(first, second); - first = current; - - while (fscanf(file, "%lf" ¤t) == 1) { - if (((current - second) > eps) && ((first - current) < eps)) count++; - } - return count; -} +// 10Ex int main(void) { FILE * file = getFile(); diff --git a/10Ex/makefile b/10Ex/makefile new file mode 100644 index 0000000..09c801c --- /dev/null +++ b/10Ex/makefile @@ -0,0 +1,11 @@ +all: main.o count_between.o tools.o + gcc main.o count_between.o tools.o && del *.o + +main.o: main.c + gcc -c main.c + +count_between.o: count_between.c + gcc -c count_between.c + +tools.o: tools.c + gcc -c tools.c \ No newline at end of file diff --git a/Second/count_elements.c b/Second/count_elements.c index e8db686..ef3828a 100644 --- a/Second/count_elements.c +++ b/Second/count_elements.c @@ -12,7 +12,7 @@ double detectNumber(double number, double count) { } double summa(double info_count) { - int count = 0.; + int count = 0; for (int i = 0; i < 5; i++) { count += fmod(info_count, 10.); diff --git a/Second/input.txt b/Second/input.txt index 6a6f29b..4f017c9 100644 --- a/Second/input.txt +++ b/Second/input.txt @@ -1,16 +1 @@ -1.5 -2 -2.5 -2 -3.5 -4 -4.5 -4 -4 -4 -4 -4 -4 -5.5 -0.5 -48 \ No newline at end of file +0.123 -1.12 1 2 1 2 1 2 3.4 5 \ No newline at end of file