From 2e4417c1dc1e6702b423d45c5cc7d15c106e639c Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Wed, 25 Sep 2024 08:00:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=2022=20?= =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 22Ex/input.txt | 1 + 22Ex/main.c | 21 +++++++++++++++++++++ 22Ex/make_increasing.c | 21 +++++++++++++++++++++ 22Ex/make_increasing.h | 12 ++++++++++++ 22Ex/makefile | 11 +++++++++++ 22Ex/tools.c | 23 +++++++++++++++++++++++ 22Ex/tools.h | 8 ++++++++ 7 files changed, 97 insertions(+) create mode 100644 22Ex/input.txt create mode 100644 22Ex/main.c create mode 100644 22Ex/make_increasing.c create mode 100644 22Ex/make_increasing.h create mode 100644 22Ex/makefile create mode 100644 22Ex/tools.c create mode 100644 22Ex/tools.h diff --git a/22Ex/input.txt b/22Ex/input.txt new file mode 100644 index 0000000..7e92570 --- /dev/null +++ b/22Ex/input.txt @@ -0,0 +1 @@ +1 2 3 4 5 \ No newline at end of file diff --git a/22Ex/main.c b/22Ex/main.c new file mode 100644 index 0000000..d11e94f --- /dev/null +++ b/22Ex/main.c @@ -0,0 +1,21 @@ +#include +#include "tools.h" +#include "make_increasing.h" + +/* +23 Task +Example: +1 2 3 4 5 - possible +2 1 3 5 4 - impossible +*/ + +int main(void) { + FILE * file = getFile(); + if (file == NULL) return 1; + if (makeIncreasing(file) != TRUE) { + printf("No, it is impossible"); + return 1; + } else printf("Yes, it is possible"); + + return 0; +} diff --git a/22Ex/make_increasing.c b/22Ex/make_increasing.c new file mode 100644 index 0000000..8f5db99 --- /dev/null +++ b/22Ex/make_increasing.c @@ -0,0 +1,21 @@ +#include "make_increasing.h" + +int makeIncreasing(FILE * file) { + double current, next; + unsigned short used = 0; + + if (fscanf(file, "%lf", ¤t) != 1) { + printf("File is empty!"); + return 0; + } + + while (fscanf(file, "%lf", &next) == 1) { + if ((next - current) < DISREG) { + if (used == TRUE) return 0; + used = TRUE; + } + current = next; + } + + return 1; +} diff --git a/22Ex/make_increasing.h b/22Ex/make_increasing.h new file mode 100644 index 0000000..1171d58 --- /dev/null +++ b/22Ex/make_increasing.h @@ -0,0 +1,12 @@ +#ifndef MAKE_INCREASING +#define MAKE_INCREASING + +#include +#include + +#define DISREG 1.e-6 +#define TRUE 1 + +int makeIncreasing(FILE * file); + +#endif diff --git a/22Ex/makefile b/22Ex/makefile new file mode 100644 index 0000000..7f54909 --- /dev/null +++ b/22Ex/makefile @@ -0,0 +1,11 @@ +all: main.o make_increasing.o tools.o + gcc main.o make_increasing.o tools.o && del *.o + +main.o: main.c + gcc -c main.c + +make_increasing.o: make_increasing.c + gcc -c make_increasing.c + +tools.o: tools.c + gcc -c tools.c \ No newline at end of file diff --git a/22Ex/tools.c b/22Ex/tools.c new file mode 100644 index 0000000..3900212 --- /dev/null +++ b/22Ex/tools.c @@ -0,0 +1,23 @@ +#include "tools.h" + +FILE * getFile(void) +{ + FILE * file; + char filename[50]; + + printf("Enter filename: "); + if (scanf("%s", filename) == 1) + { + file = fopen(filename, "r"); + if (file == NULL) { + printf("Error file!\n"); + return NULL; + } else { + return file; + } + } else + { + printf("Empty name!\n"); + return NULL; + } +} diff --git a/22Ex/tools.h b/22Ex/tools.h new file mode 100644 index 0000000..860a2a7 --- /dev/null +++ b/22Ex/tools.h @@ -0,0 +1,8 @@ +#ifndef TOOLS +#define TOOLS + +#include + +FILE * getFile(void); + +#endif