From 51dd1e537a159e1664bc1533f4e9e06a649a708b Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Fri, 27 Sep 2024 06:18:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB,=20=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BD=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=B8=D0=BB=2010=D0=B5=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5,=20TODO:=20=D0=97=D0=B0=D0=BA=D0=BE=D0=BD=D1=87=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B5=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 10Ex/main.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/10Ex/main.c b/10Ex/main.c index 8b13789..2a4841a 100644 --- a/10Ex/main.c +++ b/10Ex/main.c @@ -1 +1,42 @@ +#include +#include "tools.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; +} + +int main(void) { + FILE * file = getFile(); + if (file == NULL) return 1; + + printf("Count of number between first and second is %d", countBetween(file)); +}