From 48b359f34c465b3571a24b43e47e81f44239dc99 Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Thu, 13 Mar 2025 15:43:21 +0300 Subject: [PATCH] All tasks are done! --- 2025.03.14/{1Ex => 01Ex}/array_io.c | 0 2025.03.14/{1Ex => 01Ex}/array_io.h | 0 2025.03.14/{3Ex => 01Ex}/init_f.c | 2 +- 2025.03.14/{1Ex => 01Ex}/init_f.h | 0 2025.03.14/{2Ex => 01Ex}/io_status.h | 3 +- 2025.03.14/{1Ex => 01Ex}/main.c | 2 +- 2025.03.14/{1Ex => 01Ex}/solve.c | 0 2025.03.14/{1Ex => 01Ex}/solve.h | 0 2025.03.14/{1Ex => 01Ex}/t.txt | 0 2025.03.14/{2Ex => 02Ex}/array_io.c | 0 2025.03.14/{2Ex => 02Ex}/array_io.h | 0 2025.03.14/{1Ex => 02Ex}/init_f.c | 2 +- 2025.03.14/{2Ex => 02Ex}/init_f.h | 0 2025.03.14/{3Ex => 02Ex}/io_status.h | 3 +- 2025.03.14/{2Ex => 02Ex}/main.c | 2 +- 2025.03.14/{2Ex => 02Ex}/solve.c | 0 2025.03.14/{2Ex => 02Ex}/solve.h | 0 2025.03.14/{2Ex => 02Ex}/t.txt | 0 2025.03.14/{1Ex => 02Ex}/test_cases.json | 0 2025.03.14/{1Ex => 02Ex}/test_runner.py | 0 2025.03.14/{3Ex => 03Ex}/a.txt | 0 2025.03.14/{3Ex => 03Ex}/array_io.c | 0 2025.03.14/{3Ex => 03Ex}/array_io.h | 0 2025.03.14/{3Ex => 03Ex}/b.txt | 0 2025.03.14/{4Ex => 03Ex}/init_f.c | 2 +- 2025.03.14/{3Ex => 03Ex}/init_f.h | 0 2025.03.14/{1Ex => 03Ex}/io_status.h | 3 +- 2025.03.14/{3Ex => 03Ex}/main.c | 2 +- 2025.03.14/{3Ex => 03Ex}/solve.c | 0 2025.03.14/{3Ex => 03Ex}/solve.h | 0 2025.03.14/{3Ex => 03Ex}/x.txt | 0 2025.03.14/{4Ex => 04Ex}/a.txt | 0 2025.03.14/{4Ex => 04Ex}/array_io.c | 0 2025.03.14/{4Ex => 04Ex}/array_io.h | 0 2025.03.14/{4Ex => 04Ex}/b.txt | 0 2025.03.14/{2Ex => 04Ex}/init_f.c | 2 +- 2025.03.14/{4Ex => 04Ex}/init_f.h | 0 2025.03.14/{4Ex => 04Ex}/io_status.h | 3 +- 2025.03.14/{4Ex => 04Ex}/main.c | 2 +- 2025.03.14/{4Ex => 04Ex}/solve.c | 0 2025.03.14/{4Ex => 04Ex}/solve.h | 0 2025.03.14/{4Ex => 04Ex}/x.txt | 0 2025.03.14/{5Ex => 05Ex}/a.txt | 0 2025.03.14/{5Ex => 05Ex}/b.txt | 0 2025.03.14/05Ex/init_f.c | 30 +++ 2025.03.14/{5Ex => 05Ex}/init_f.h | 0 2025.03.14/05Ex/io_status.h | 13 ++ 2025.03.14/{5Ex => 05Ex}/main.c | 6 +- 2025.03.14/{5Ex => 05Ex}/solve.c | 0 2025.03.14/{5Ex => 05Ex}/solve.h | 0 2025.03.14/06Ex/a.txt | 5 + 2025.03.14/{5Ex => 06Ex}/array_io.c | 0 2025.03.14/{5Ex => 06Ex}/array_io.h | 0 2025.03.14/06Ex/b.txt | 4 + 2025.03.14/06Ex/init_f.c | 30 +++ 2025.03.14/06Ex/init_f.h | 9 + 2025.03.14/06Ex/io_status.h | 13 ++ 2025.03.14/06Ex/main.c | 110 +++++++++++ 2025.03.14/06Ex/solve.c | 38 ++++ 2025.03.14/06Ex/solve.h | 7 + 2025.03.14/07Ex/array_io.c | 40 ++++ 2025.03.14/07Ex/array_io.h | 11 ++ 2025.03.14/07Ex/init_f.c | 30 +++ 2025.03.14/07Ex/init_f.h | 9 + 2025.03.14/07Ex/io_status.h | 13 ++ 2025.03.14/07Ex/main.c | 67 +++++++ 2025.03.14/07Ex/solve.c | 32 +++ 2025.03.14/07Ex/solve.h | 7 + 2025.03.14/07Ex/t.txt | 5 + 2025.03.14/08Ex/a.txt | 3 + 2025.03.14/08Ex/array_io.c | 40 ++++ 2025.03.14/08Ex/array_io.h | 11 ++ 2025.03.14/08Ex/init_f.c | 30 +++ 2025.03.14/08Ex/init_f.h | 9 + 2025.03.14/08Ex/io_status.h | 13 ++ 2025.03.14/08Ex/main.c | 67 +++++++ 2025.03.14/08Ex/solve.c | 32 +++ 2025.03.14/08Ex/solve.h | 7 + 2025.03.14/09Ex/a.txt | 3 + 2025.03.14/09Ex/array_io.c | 40 ++++ 2025.03.14/09Ex/array_io.h | 11 ++ 2025.03.14/09Ex/init_f.c | 30 +++ 2025.03.14/09Ex/init_f.h | 9 + 2025.03.14/09Ex/io_status.h | 13 ++ 2025.03.14/09Ex/main.c | 67 +++++++ 2025.03.14/09Ex/solve.c | 32 +++ 2025.03.14/09Ex/solve.h | 7 + 2025.03.14/10Ex/a.txt | 3 + 2025.03.14/10Ex/array_io.c | 40 ++++ 2025.03.14/10Ex/array_io.h | 11 ++ 2025.03.14/10Ex/init_f.c | 30 +++ 2025.03.14/10Ex/init_f.h | 9 + 2025.03.14/10Ex/io_status.h | 13 ++ 2025.03.14/10Ex/main.c | 67 +++++++ 2025.03.14/10Ex/solve.c | 32 +++ 2025.03.14/10Ex/solve.h | 7 + 2025.03.14/11Ex/a.txt | 3 + 2025.03.14/11Ex/array_io.c | 40 ++++ 2025.03.14/11Ex/array_io.h | 11 ++ 2025.03.14/11Ex/init_f.c | 30 +++ 2025.03.14/11Ex/init_f.h | 9 + 2025.03.14/11Ex/io_status.h | 13 ++ 2025.03.14/11Ex/main.c | 67 +++++++ 2025.03.14/11Ex/solve.c | 41 ++++ 2025.03.14/11Ex/solve.h | 7 + 2025.03.14/1Ex/Makefile | 19 -- 2025.03.14/2Ex/Makefile | 19 -- 2025.03.14/2Ex/test_cases.json | 123 ------------ 2025.03.14/2Ex/test_runner.py | 176 ----------------- 2025.03.14/3Ex/Makefile | 19 -- 2025.03.14/4Ex/Makefile | 19 -- 2025.03.14/5Ex/init_f.c | 30 --- 2025.03.14/5Ex/io_status.h | 14 -- 2025.03.14/Linux/a01.c | 65 ++++++ 2025.03.14/Linux/a02.c | 65 ++++++ 2025.03.14/Linux/a03.c | 161 +++++++++++++++ 2025.03.14/Linux/a04.c | 161 +++++++++++++++ 2025.03.14/Linux/a05.c | 110 +++++++++++ 2025.03.14/Linux/a06.c | 110 +++++++++++ 2025.03.14/Linux/a07.c | 67 +++++++ 2025.03.14/Linux/a08.c | 67 +++++++ 2025.03.14/Linux/a09.c | 67 +++++++ 2025.03.14/Linux/a10.c | 67 +++++++ 2025.03.14/Linux/a11.c | 67 +++++++ 2025.03.14/Linux/array_io.c | 40 ++++ 2025.03.14/Linux/array_io.h | 11 ++ 2025.03.14/Linux/init_f.c | 30 +++ 2025.03.14/Linux/init_f.h | 9 + 2025.03.14/Linux/io_status.h | 13 ++ 2025.03.14/Linux/solve.c | 241 +++++++++++++++++++++++ 2025.03.14/Linux/solve.h | 17 ++ 131 files changed, 2713 insertions(+), 438 deletions(-) rename 2025.03.14/{1Ex => 01Ex}/array_io.c (100%) rename 2025.03.14/{1Ex => 01Ex}/array_io.h (100%) rename 2025.03.14/{3Ex => 01Ex}/init_f.c (95%) rename 2025.03.14/{1Ex => 01Ex}/init_f.h (100%) rename 2025.03.14/{2Ex => 01Ex}/io_status.h (84%) rename 2025.03.14/{1Ex => 01Ex}/main.c (97%) rename 2025.03.14/{1Ex => 01Ex}/solve.c (100%) rename 2025.03.14/{1Ex => 01Ex}/solve.h (100%) rename 2025.03.14/{1Ex => 01Ex}/t.txt (100%) rename 2025.03.14/{2Ex => 02Ex}/array_io.c (100%) rename 2025.03.14/{2Ex => 02Ex}/array_io.h (100%) rename 2025.03.14/{1Ex => 02Ex}/init_f.c (95%) rename 2025.03.14/{2Ex => 02Ex}/init_f.h (100%) rename 2025.03.14/{3Ex => 02Ex}/io_status.h (84%) rename 2025.03.14/{2Ex => 02Ex}/main.c (97%) rename 2025.03.14/{2Ex => 02Ex}/solve.c (100%) rename 2025.03.14/{2Ex => 02Ex}/solve.h (100%) rename 2025.03.14/{2Ex => 02Ex}/t.txt (100%) rename 2025.03.14/{1Ex => 02Ex}/test_cases.json (100%) rename 2025.03.14/{1Ex => 02Ex}/test_runner.py (100%) rename 2025.03.14/{3Ex => 03Ex}/a.txt (100%) rename 2025.03.14/{3Ex => 03Ex}/array_io.c (100%) rename 2025.03.14/{3Ex => 03Ex}/array_io.h (100%) rename 2025.03.14/{3Ex => 03Ex}/b.txt (100%) rename 2025.03.14/{4Ex => 03Ex}/init_f.c (95%) rename 2025.03.14/{3Ex => 03Ex}/init_f.h (100%) rename 2025.03.14/{1Ex => 03Ex}/io_status.h (84%) rename 2025.03.14/{3Ex => 03Ex}/main.c (99%) rename 2025.03.14/{3Ex => 03Ex}/solve.c (100%) rename 2025.03.14/{3Ex => 03Ex}/solve.h (100%) rename 2025.03.14/{3Ex => 03Ex}/x.txt (100%) rename 2025.03.14/{4Ex => 04Ex}/a.txt (100%) rename 2025.03.14/{4Ex => 04Ex}/array_io.c (100%) rename 2025.03.14/{4Ex => 04Ex}/array_io.h (100%) rename 2025.03.14/{4Ex => 04Ex}/b.txt (100%) rename 2025.03.14/{2Ex => 04Ex}/init_f.c (95%) rename 2025.03.14/{4Ex => 04Ex}/init_f.h (100%) rename 2025.03.14/{4Ex => 04Ex}/io_status.h (84%) rename 2025.03.14/{4Ex => 04Ex}/main.c (99%) rename 2025.03.14/{4Ex => 04Ex}/solve.c (100%) rename 2025.03.14/{4Ex => 04Ex}/solve.h (100%) rename 2025.03.14/{4Ex => 04Ex}/x.txt (100%) rename 2025.03.14/{5Ex => 05Ex}/a.txt (100%) rename 2025.03.14/{5Ex => 05Ex}/b.txt (100%) create mode 100644 2025.03.14/05Ex/init_f.c rename 2025.03.14/{5Ex => 05Ex}/init_f.h (100%) create mode 100644 2025.03.14/05Ex/io_status.h rename 2025.03.14/{5Ex => 05Ex}/main.c (96%) rename 2025.03.14/{5Ex => 05Ex}/solve.c (100%) rename 2025.03.14/{5Ex => 05Ex}/solve.h (100%) create mode 100644 2025.03.14/06Ex/a.txt rename 2025.03.14/{5Ex => 06Ex}/array_io.c (100%) rename 2025.03.14/{5Ex => 06Ex}/array_io.h (100%) create mode 100644 2025.03.14/06Ex/b.txt create mode 100644 2025.03.14/06Ex/init_f.c create mode 100644 2025.03.14/06Ex/init_f.h create mode 100644 2025.03.14/06Ex/io_status.h create mode 100644 2025.03.14/06Ex/main.c create mode 100644 2025.03.14/06Ex/solve.c create mode 100644 2025.03.14/06Ex/solve.h create mode 100644 2025.03.14/07Ex/array_io.c create mode 100644 2025.03.14/07Ex/array_io.h create mode 100644 2025.03.14/07Ex/init_f.c create mode 100644 2025.03.14/07Ex/init_f.h create mode 100644 2025.03.14/07Ex/io_status.h create mode 100644 2025.03.14/07Ex/main.c create mode 100644 2025.03.14/07Ex/solve.c create mode 100644 2025.03.14/07Ex/solve.h create mode 100644 2025.03.14/07Ex/t.txt create mode 100644 2025.03.14/08Ex/a.txt create mode 100644 2025.03.14/08Ex/array_io.c create mode 100644 2025.03.14/08Ex/array_io.h create mode 100644 2025.03.14/08Ex/init_f.c create mode 100644 2025.03.14/08Ex/init_f.h create mode 100644 2025.03.14/08Ex/io_status.h create mode 100644 2025.03.14/08Ex/main.c create mode 100644 2025.03.14/08Ex/solve.c create mode 100644 2025.03.14/08Ex/solve.h create mode 100644 2025.03.14/09Ex/a.txt create mode 100644 2025.03.14/09Ex/array_io.c create mode 100644 2025.03.14/09Ex/array_io.h create mode 100644 2025.03.14/09Ex/init_f.c create mode 100644 2025.03.14/09Ex/init_f.h create mode 100644 2025.03.14/09Ex/io_status.h create mode 100644 2025.03.14/09Ex/main.c create mode 100644 2025.03.14/09Ex/solve.c create mode 100644 2025.03.14/09Ex/solve.h create mode 100644 2025.03.14/10Ex/a.txt create mode 100644 2025.03.14/10Ex/array_io.c create mode 100644 2025.03.14/10Ex/array_io.h create mode 100644 2025.03.14/10Ex/init_f.c create mode 100644 2025.03.14/10Ex/init_f.h create mode 100644 2025.03.14/10Ex/io_status.h create mode 100644 2025.03.14/10Ex/main.c create mode 100644 2025.03.14/10Ex/solve.c create mode 100644 2025.03.14/10Ex/solve.h create mode 100644 2025.03.14/11Ex/a.txt create mode 100644 2025.03.14/11Ex/array_io.c create mode 100644 2025.03.14/11Ex/array_io.h create mode 100644 2025.03.14/11Ex/init_f.c create mode 100644 2025.03.14/11Ex/init_f.h create mode 100644 2025.03.14/11Ex/io_status.h create mode 100644 2025.03.14/11Ex/main.c create mode 100644 2025.03.14/11Ex/solve.c create mode 100644 2025.03.14/11Ex/solve.h delete mode 100644 2025.03.14/1Ex/Makefile delete mode 100644 2025.03.14/2Ex/Makefile delete mode 100644 2025.03.14/2Ex/test_cases.json delete mode 100644 2025.03.14/2Ex/test_runner.py delete mode 100644 2025.03.14/3Ex/Makefile delete mode 100644 2025.03.14/4Ex/Makefile delete mode 100644 2025.03.14/5Ex/init_f.c delete mode 100644 2025.03.14/5Ex/io_status.h create mode 100644 2025.03.14/Linux/a01.c create mode 100644 2025.03.14/Linux/a02.c create mode 100644 2025.03.14/Linux/a03.c create mode 100644 2025.03.14/Linux/a04.c create mode 100644 2025.03.14/Linux/a05.c create mode 100644 2025.03.14/Linux/a06.c create mode 100644 2025.03.14/Linux/a07.c create mode 100644 2025.03.14/Linux/a08.c create mode 100644 2025.03.14/Linux/a09.c create mode 100644 2025.03.14/Linux/a10.c create mode 100644 2025.03.14/Linux/a11.c create mode 100644 2025.03.14/Linux/array_io.c create mode 100644 2025.03.14/Linux/array_io.h create mode 100644 2025.03.14/Linux/init_f.c create mode 100644 2025.03.14/Linux/init_f.h create mode 100644 2025.03.14/Linux/io_status.h create mode 100644 2025.03.14/Linux/solve.c create mode 100644 2025.03.14/Linux/solve.h diff --git a/2025.03.14/1Ex/array_io.c b/2025.03.14/01Ex/array_io.c similarity index 100% rename from 2025.03.14/1Ex/array_io.c rename to 2025.03.14/01Ex/array_io.c diff --git a/2025.03.14/1Ex/array_io.h b/2025.03.14/01Ex/array_io.h similarity index 100% rename from 2025.03.14/1Ex/array_io.h rename to 2025.03.14/01Ex/array_io.h diff --git a/2025.03.14/3Ex/init_f.c b/2025.03.14/01Ex/init_f.c similarity index 95% rename from 2025.03.14/3Ex/init_f.c rename to 2025.03.14/01Ex/init_f.c index cf325c3..925afb5 100644 --- a/2025.03.14/3Ex/init_f.c +++ b/2025.03.14/01Ex/init_f.c @@ -1,5 +1,5 @@ #include "init_f.h" -#include +#include #define MAX(n, m) (n < m ? m : n) diff --git a/2025.03.14/1Ex/init_f.h b/2025.03.14/01Ex/init_f.h similarity index 100% rename from 2025.03.14/1Ex/init_f.h rename to 2025.03.14/01Ex/init_f.h diff --git a/2025.03.14/2Ex/io_status.h b/2025.03.14/01Ex/io_status.h similarity index 84% rename from 2025.03.14/2Ex/io_status.h rename to 2025.03.14/01Ex/io_status.h index a51376d..420a981 100644 --- a/2025.03.14/2Ex/io_status.h +++ b/2025.03.14/01Ex/io_status.h @@ -7,8 +7,7 @@ typedef enum _io_status { SUCCESS, ERROR_OPEN, - ERROR_READ, - ERROR_MEM + ERROR_READ } io_status; #endif diff --git a/2025.03.14/1Ex/main.c b/2025.03.14/01Ex/main.c similarity index 97% rename from 2025.03.14/1Ex/main.c rename to 2025.03.14/01Ex/main.c index 9f23202..0631900 100644 --- a/2025.03.14/1Ex/main.c +++ b/2025.03.14/01Ex/main.c @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) } while (0); } else init_matrix(a, n, m, k); - printf("Initial matrix:\n"); + printf("Matrix:\n"); print_matrix(a, n, m, p); t = clock(); diff --git a/2025.03.14/1Ex/solve.c b/2025.03.14/01Ex/solve.c similarity index 100% rename from 2025.03.14/1Ex/solve.c rename to 2025.03.14/01Ex/solve.c diff --git a/2025.03.14/1Ex/solve.h b/2025.03.14/01Ex/solve.h similarity index 100% rename from 2025.03.14/1Ex/solve.h rename to 2025.03.14/01Ex/solve.h diff --git a/2025.03.14/1Ex/t.txt b/2025.03.14/01Ex/t.txt similarity index 100% rename from 2025.03.14/1Ex/t.txt rename to 2025.03.14/01Ex/t.txt diff --git a/2025.03.14/2Ex/array_io.c b/2025.03.14/02Ex/array_io.c similarity index 100% rename from 2025.03.14/2Ex/array_io.c rename to 2025.03.14/02Ex/array_io.c diff --git a/2025.03.14/2Ex/array_io.h b/2025.03.14/02Ex/array_io.h similarity index 100% rename from 2025.03.14/2Ex/array_io.h rename to 2025.03.14/02Ex/array_io.h diff --git a/2025.03.14/1Ex/init_f.c b/2025.03.14/02Ex/init_f.c similarity index 95% rename from 2025.03.14/1Ex/init_f.c rename to 2025.03.14/02Ex/init_f.c index cf325c3..925afb5 100644 --- a/2025.03.14/1Ex/init_f.c +++ b/2025.03.14/02Ex/init_f.c @@ -1,5 +1,5 @@ #include "init_f.h" -#include +#include #define MAX(n, m) (n < m ? m : n) diff --git a/2025.03.14/2Ex/init_f.h b/2025.03.14/02Ex/init_f.h similarity index 100% rename from 2025.03.14/2Ex/init_f.h rename to 2025.03.14/02Ex/init_f.h diff --git a/2025.03.14/3Ex/io_status.h b/2025.03.14/02Ex/io_status.h similarity index 84% rename from 2025.03.14/3Ex/io_status.h rename to 2025.03.14/02Ex/io_status.h index a51376d..420a981 100644 --- a/2025.03.14/3Ex/io_status.h +++ b/2025.03.14/02Ex/io_status.h @@ -7,8 +7,7 @@ typedef enum _io_status { SUCCESS, ERROR_OPEN, - ERROR_READ, - ERROR_MEM + ERROR_READ } io_status; #endif diff --git a/2025.03.14/2Ex/main.c b/2025.03.14/02Ex/main.c similarity index 97% rename from 2025.03.14/2Ex/main.c rename to 2025.03.14/02Ex/main.c index 42541fc..d53bed3 100644 --- a/2025.03.14/2Ex/main.c +++ b/2025.03.14/02Ex/main.c @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) } while (0); } else init_matrix(a, n, m, k); - printf("Initial matrix:\n"); + printf("Matrix:\n"); print_matrix(a, n, m, p); t = clock(); diff --git a/2025.03.14/2Ex/solve.c b/2025.03.14/02Ex/solve.c similarity index 100% rename from 2025.03.14/2Ex/solve.c rename to 2025.03.14/02Ex/solve.c diff --git a/2025.03.14/2Ex/solve.h b/2025.03.14/02Ex/solve.h similarity index 100% rename from 2025.03.14/2Ex/solve.h rename to 2025.03.14/02Ex/solve.h diff --git a/2025.03.14/2Ex/t.txt b/2025.03.14/02Ex/t.txt similarity index 100% rename from 2025.03.14/2Ex/t.txt rename to 2025.03.14/02Ex/t.txt diff --git a/2025.03.14/1Ex/test_cases.json b/2025.03.14/02Ex/test_cases.json similarity index 100% rename from 2025.03.14/1Ex/test_cases.json rename to 2025.03.14/02Ex/test_cases.json diff --git a/2025.03.14/1Ex/test_runner.py b/2025.03.14/02Ex/test_runner.py similarity index 100% rename from 2025.03.14/1Ex/test_runner.py rename to 2025.03.14/02Ex/test_runner.py diff --git a/2025.03.14/3Ex/a.txt b/2025.03.14/03Ex/a.txt similarity index 100% rename from 2025.03.14/3Ex/a.txt rename to 2025.03.14/03Ex/a.txt diff --git a/2025.03.14/3Ex/array_io.c b/2025.03.14/03Ex/array_io.c similarity index 100% rename from 2025.03.14/3Ex/array_io.c rename to 2025.03.14/03Ex/array_io.c diff --git a/2025.03.14/3Ex/array_io.h b/2025.03.14/03Ex/array_io.h similarity index 100% rename from 2025.03.14/3Ex/array_io.h rename to 2025.03.14/03Ex/array_io.h diff --git a/2025.03.14/3Ex/b.txt b/2025.03.14/03Ex/b.txt similarity index 100% rename from 2025.03.14/3Ex/b.txt rename to 2025.03.14/03Ex/b.txt diff --git a/2025.03.14/4Ex/init_f.c b/2025.03.14/03Ex/init_f.c similarity index 95% rename from 2025.03.14/4Ex/init_f.c rename to 2025.03.14/03Ex/init_f.c index cf325c3..925afb5 100644 --- a/2025.03.14/4Ex/init_f.c +++ b/2025.03.14/03Ex/init_f.c @@ -1,5 +1,5 @@ #include "init_f.h" -#include +#include #define MAX(n, m) (n < m ? m : n) diff --git a/2025.03.14/3Ex/init_f.h b/2025.03.14/03Ex/init_f.h similarity index 100% rename from 2025.03.14/3Ex/init_f.h rename to 2025.03.14/03Ex/init_f.h diff --git a/2025.03.14/1Ex/io_status.h b/2025.03.14/03Ex/io_status.h similarity index 84% rename from 2025.03.14/1Ex/io_status.h rename to 2025.03.14/03Ex/io_status.h index a51376d..420a981 100644 --- a/2025.03.14/1Ex/io_status.h +++ b/2025.03.14/03Ex/io_status.h @@ -7,8 +7,7 @@ typedef enum _io_status { SUCCESS, ERROR_OPEN, - ERROR_READ, - ERROR_MEM + ERROR_READ } io_status; #endif diff --git a/2025.03.14/3Ex/main.c b/2025.03.14/03Ex/main.c similarity index 99% rename from 2025.03.14/3Ex/main.c rename to 2025.03.14/03Ex/main.c index 2071813..785fa2a 100644 --- a/2025.03.14/3Ex/main.c +++ b/2025.03.14/03Ex/main.c @@ -140,7 +140,7 @@ int main(int argc, char *argv[]) } else init_matrix(x, m, 1, k_x); - printf("Initial matrix A:\n"); + printf("Matrix:\n"); print_matrix(a, n, m, p); printf("Initial vector b:\n"); print_matrix(b, n, 1, p); diff --git a/2025.03.14/3Ex/solve.c b/2025.03.14/03Ex/solve.c similarity index 100% rename from 2025.03.14/3Ex/solve.c rename to 2025.03.14/03Ex/solve.c diff --git a/2025.03.14/3Ex/solve.h b/2025.03.14/03Ex/solve.h similarity index 100% rename from 2025.03.14/3Ex/solve.h rename to 2025.03.14/03Ex/solve.h diff --git a/2025.03.14/3Ex/x.txt b/2025.03.14/03Ex/x.txt similarity index 100% rename from 2025.03.14/3Ex/x.txt rename to 2025.03.14/03Ex/x.txt diff --git a/2025.03.14/4Ex/a.txt b/2025.03.14/04Ex/a.txt similarity index 100% rename from 2025.03.14/4Ex/a.txt rename to 2025.03.14/04Ex/a.txt diff --git a/2025.03.14/4Ex/array_io.c b/2025.03.14/04Ex/array_io.c similarity index 100% rename from 2025.03.14/4Ex/array_io.c rename to 2025.03.14/04Ex/array_io.c diff --git a/2025.03.14/4Ex/array_io.h b/2025.03.14/04Ex/array_io.h similarity index 100% rename from 2025.03.14/4Ex/array_io.h rename to 2025.03.14/04Ex/array_io.h diff --git a/2025.03.14/4Ex/b.txt b/2025.03.14/04Ex/b.txt similarity index 100% rename from 2025.03.14/4Ex/b.txt rename to 2025.03.14/04Ex/b.txt diff --git a/2025.03.14/2Ex/init_f.c b/2025.03.14/04Ex/init_f.c similarity index 95% rename from 2025.03.14/2Ex/init_f.c rename to 2025.03.14/04Ex/init_f.c index cf325c3..925afb5 100644 --- a/2025.03.14/2Ex/init_f.c +++ b/2025.03.14/04Ex/init_f.c @@ -1,5 +1,5 @@ #include "init_f.h" -#include +#include #define MAX(n, m) (n < m ? m : n) diff --git a/2025.03.14/4Ex/init_f.h b/2025.03.14/04Ex/init_f.h similarity index 100% rename from 2025.03.14/4Ex/init_f.h rename to 2025.03.14/04Ex/init_f.h diff --git a/2025.03.14/4Ex/io_status.h b/2025.03.14/04Ex/io_status.h similarity index 84% rename from 2025.03.14/4Ex/io_status.h rename to 2025.03.14/04Ex/io_status.h index a51376d..420a981 100644 --- a/2025.03.14/4Ex/io_status.h +++ b/2025.03.14/04Ex/io_status.h @@ -7,8 +7,7 @@ typedef enum _io_status { SUCCESS, ERROR_OPEN, - ERROR_READ, - ERROR_MEM + ERROR_READ } io_status; #endif diff --git a/2025.03.14/4Ex/main.c b/2025.03.14/04Ex/main.c similarity index 99% rename from 2025.03.14/4Ex/main.c rename to 2025.03.14/04Ex/main.c index 91daa07..4118184 100644 --- a/2025.03.14/4Ex/main.c +++ b/2025.03.14/04Ex/main.c @@ -140,7 +140,7 @@ int main(int argc, char *argv[]) } else init_matrix(x, m, 1, k_x); - printf("Initial matrix A:\n"); + printf("Matrix:\n"); print_matrix(a, n, m, p); printf("Initial vector b:\n"); print_matrix(b, n, 1, p); diff --git a/2025.03.14/4Ex/solve.c b/2025.03.14/04Ex/solve.c similarity index 100% rename from 2025.03.14/4Ex/solve.c rename to 2025.03.14/04Ex/solve.c diff --git a/2025.03.14/4Ex/solve.h b/2025.03.14/04Ex/solve.h similarity index 100% rename from 2025.03.14/4Ex/solve.h rename to 2025.03.14/04Ex/solve.h diff --git a/2025.03.14/4Ex/x.txt b/2025.03.14/04Ex/x.txt similarity index 100% rename from 2025.03.14/4Ex/x.txt rename to 2025.03.14/04Ex/x.txt diff --git a/2025.03.14/5Ex/a.txt b/2025.03.14/05Ex/a.txt similarity index 100% rename from 2025.03.14/5Ex/a.txt rename to 2025.03.14/05Ex/a.txt diff --git a/2025.03.14/5Ex/b.txt b/2025.03.14/05Ex/b.txt similarity index 100% rename from 2025.03.14/5Ex/b.txt rename to 2025.03.14/05Ex/b.txt diff --git a/2025.03.14/05Ex/init_f.c b/2025.03.14/05Ex/init_f.c new file mode 100644 index 0000000..925afb5 --- /dev/null +++ b/2025.03.14/05Ex/init_f.c @@ -0,0 +1,30 @@ +#include "init_f.h" +#include + +#define MAX(n, m) (n < m ? m : n) + +double f1(int n, int m, int i, int j) +{ + return MAX(n, m) - MAX(i, j) + 1; +} + +double f2(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return MAX(i, j); +} + +double f3(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return abs(i - j); +} + +double f4(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return 1./(i+j-1); +} diff --git a/2025.03.14/5Ex/init_f.h b/2025.03.14/05Ex/init_f.h similarity index 100% rename from 2025.03.14/5Ex/init_f.h rename to 2025.03.14/05Ex/init_f.h diff --git a/2025.03.14/05Ex/io_status.h b/2025.03.14/05Ex/io_status.h new file mode 100644 index 0000000..420a981 --- /dev/null +++ b/2025.03.14/05Ex/io_status.h @@ -0,0 +1,13 @@ +#ifndef IO_STATUS_H +#define IO_STATUS_H + +#define LEN 1234 + +typedef enum _io_status +{ + SUCCESS, + ERROR_OPEN, + ERROR_READ +} io_status; + +#endif diff --git a/2025.03.14/5Ex/main.c b/2025.03.14/05Ex/main.c similarity index 96% rename from 2025.03.14/5Ex/main.c rename to 2025.03.14/05Ex/main.c index 67753c7..814b3ff 100644 --- a/2025.03.14/5Ex/main.c +++ b/2025.03.14/05Ex/main.c @@ -92,13 +92,13 @@ int main(int argc, char *argv[]) } while (0); } else init_matrix(b, m, n, k_b); - printf("Initial matrix A:\n"); + printf("Matrix A:\n"); print_matrix(a, n, m, p); - printf("Initial matrix b:\n"); + printf("Matrix B:\n"); print_matrix(b, m, n, p); t = clock(); - t5_solve(a, b, n, m); + res = t5_solve(a, b, n, m); t = (clock() - t) / CLOCKS_PER_SEC; printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); diff --git a/2025.03.14/5Ex/solve.c b/2025.03.14/05Ex/solve.c similarity index 100% rename from 2025.03.14/5Ex/solve.c rename to 2025.03.14/05Ex/solve.c diff --git a/2025.03.14/5Ex/solve.h b/2025.03.14/05Ex/solve.h similarity index 100% rename from 2025.03.14/5Ex/solve.h rename to 2025.03.14/05Ex/solve.h diff --git a/2025.03.14/06Ex/a.txt b/2025.03.14/06Ex/a.txt new file mode 100644 index 0000000..ab47978 --- /dev/null +++ b/2025.03.14/06Ex/a.txt @@ -0,0 +1,5 @@ +1 2 3 4 +4 3 2 1 +1 2 3 4 +4 3 2 1 +1 2 3 4 diff --git a/2025.03.14/5Ex/array_io.c b/2025.03.14/06Ex/array_io.c similarity index 100% rename from 2025.03.14/5Ex/array_io.c rename to 2025.03.14/06Ex/array_io.c diff --git a/2025.03.14/5Ex/array_io.h b/2025.03.14/06Ex/array_io.h similarity index 100% rename from 2025.03.14/5Ex/array_io.h rename to 2025.03.14/06Ex/array_io.h diff --git a/2025.03.14/06Ex/b.txt b/2025.03.14/06Ex/b.txt new file mode 100644 index 0000000..94ebaf9 --- /dev/null +++ b/2025.03.14/06Ex/b.txt @@ -0,0 +1,4 @@ +1 +2 +3 +4 diff --git a/2025.03.14/06Ex/init_f.c b/2025.03.14/06Ex/init_f.c new file mode 100644 index 0000000..925afb5 --- /dev/null +++ b/2025.03.14/06Ex/init_f.c @@ -0,0 +1,30 @@ +#include "init_f.h" +#include + +#define MAX(n, m) (n < m ? m : n) + +double f1(int n, int m, int i, int j) +{ + return MAX(n, m) - MAX(i, j) + 1; +} + +double f2(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return MAX(i, j); +} + +double f3(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return abs(i - j); +} + +double f4(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return 1./(i+j-1); +} diff --git a/2025.03.14/06Ex/init_f.h b/2025.03.14/06Ex/init_f.h new file mode 100644 index 0000000..691aace --- /dev/null +++ b/2025.03.14/06Ex/init_f.h @@ -0,0 +1,9 @@ +#ifndef INIT_F_H +#define INIT_F_H + +double f1(int n, int m, int i, int j); +double f2(int n, int m, int i, int j); +double f3(int n, int m, int i, int j); +double f4(int n, int m, int i, int j); + +#endif diff --git a/2025.03.14/06Ex/io_status.h b/2025.03.14/06Ex/io_status.h new file mode 100644 index 0000000..420a981 --- /dev/null +++ b/2025.03.14/06Ex/io_status.h @@ -0,0 +1,13 @@ +#ifndef IO_STATUS_H +#define IO_STATUS_H + +#define LEN 1234 + +typedef enum _io_status +{ + SUCCESS, + ERROR_OPEN, + ERROR_READ +} io_status; + +#endif diff --git a/2025.03.14/06Ex/main.c b/2025.03.14/06Ex/main.c new file mode 100644 index 0000000..c97210d --- /dev/null +++ b/2025.03.14/06Ex/main.c @@ -0,0 +1,110 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k_a [filename_a] k_b [filename_b] */ +int main(int argc, char *argv[]) +{ + double t, res, *a, *b; + int n, m, p, k_a, k_b, task = 6; + char *name_a = 0, *name_b = 0; + if (!((argc == 6 || argc == 7 || argc == 8) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k_a) == 1 && + (k_a >= 0 && k_a <= 4) && + (!(k_a == 0 && argc == 6)) && + ((k_a == 0 && sscanf(argv[6], "%d", &k_b) == 1) || + (k_a != 0 && sscanf(argv[5], "%d", &k_b) == 1)) && + (k_b >= 0 && k_b <= 4) && + (!(k_b == 0 && argc == 6)) && + (!((k_a == 0 && k_b == 0) && argc != 8)))) + { + printf("Usage: %s n m p k_a [filename_a] k_b [filename_b]\n", argv[0]); + return 1; + } + if (argc != 6) + { + int i_b = 6; + if (k_a == 0) {name_a = argv[5];i_b++;} + if (k_b == 0) name_b = argv[i_b]; + } + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + b = (double *)malloc(m * n * sizeof(double)); + if (!b) + { + free(a); + printf("Not enough memory\n"); + return 2; + } + + if (name_a) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name_a); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_a); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_a); + break; + } + free(a); + free(b); + return 3; + } while (0); + } else init_matrix(a, n, m, k_a); + + if (name_b) + { + io_status ret; + ret = read_matrix(b, m, n, name_b); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_b); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_b); + break; + } + free(a); + free(b); + return 3; + } while (0); + } else init_matrix(b, m, n, k_b); + + printf("Matrix A:\n"); + print_matrix(a, n, m, p); + printf("Matrix B:\n"); + print_matrix(b, m, n, p); + + t = clock(); + res = t6_solve(a, b, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + free(b); + + return 0; +} diff --git a/2025.03.14/06Ex/solve.c b/2025.03.14/06Ex/solve.c new file mode 100644 index 0000000..924e9dc --- /dev/null +++ b/2025.03.14/06Ex/solve.c @@ -0,0 +1,38 @@ +#include "solve.h" +#include "math.h" + +#define eps 1e-9 + +int compare(const double a, const double b) +{ + if (a - b > eps) return 1; + else if (b - a > eps) return -1; + return 0; +} + +double t6_solve(const double *A, const double *b, int n, int m) +{ + double temp, summa, maximum = 0; + int i, j, k; + + if (n <= 0 || m <= 0) return 0; + + + for (k = 0; k < n; k++) + { + summa = 0; + for (i = 0; i < n; i++) + { + temp = 0; + for (j = 0; j < m; j++) + temp += A[i * m + j] * b[j * n + k]; + + if (k == i) temp--; + summa += fabs(temp); + } + if (compare(summa, maximum) == 1) maximum = summa; + } + + return maximum; +} + diff --git a/2025.03.14/06Ex/solve.h b/2025.03.14/06Ex/solve.h new file mode 100644 index 0000000..0bc32f6 --- /dev/null +++ b/2025.03.14/06Ex/solve.h @@ -0,0 +1,7 @@ +#ifndef SOLVE_H +#define SOLVE_H + +int compare(const double a, const double b); +double t6_solve(const double *A, const double *b, int n, int m); + +#endif diff --git a/2025.03.14/07Ex/array_io.c b/2025.03.14/07Ex/array_io.c new file mode 100644 index 0000000..6e56ecf --- /dev/null +++ b/2025.03.14/07Ex/array_io.c @@ -0,0 +1,40 @@ +#include +#include "array_io.h" + +io_status read_matrix(double *a, int n, int m, const char *name) +{ + int i, j; + FILE *fp; + if (!(fp = fopen(name, "r"))) return ERROR_OPEN; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (fscanf(fp, "%lf", a + i * m + j) != 1) + {fclose(fp); return ERROR_READ;} + fclose(fp); + return SUCCESS; +} + +void print_matrix(const double *a, int n, int m, int p) +{ + int np = (n > p ? p : n); + int mp = (m > p ? p : m); + int i, j; + + for (i = 0; i < np; i++) + { + for (j = 0; j < mp; j++) + printf(" %10.3e", a[i * m + j]); + printf("\n"); + } +} + +void init_matrix(double *a, int n, int m, int k) +{ + double (*q)(int, int, int, int); + double (*f[])(int, int, int, int) = {f1, f2, f3, f4}; + int i, j; + q = f[k-1]; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + a[i * m + j] = q(n, m, i+1, j+1); +} diff --git a/2025.03.14/07Ex/array_io.h b/2025.03.14/07Ex/array_io.h new file mode 100644 index 0000000..e312a84 --- /dev/null +++ b/2025.03.14/07Ex/array_io.h @@ -0,0 +1,11 @@ +#ifndef ARRAY_IO_H +#define ARRAY_IO_H + +#include "io_status.h" +#include "init_f.h" + +io_status read_matrix(double *a, int n, int m, const char *name); +void print_matrix(const double *a, int n, int m, int p); +void init_matrix(double *a, int n, int m, int k); + +#endif diff --git a/2025.03.14/07Ex/init_f.c b/2025.03.14/07Ex/init_f.c new file mode 100644 index 0000000..925afb5 --- /dev/null +++ b/2025.03.14/07Ex/init_f.c @@ -0,0 +1,30 @@ +#include "init_f.h" +#include + +#define MAX(n, m) (n < m ? m : n) + +double f1(int n, int m, int i, int j) +{ + return MAX(n, m) - MAX(i, j) + 1; +} + +double f2(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return MAX(i, j); +} + +double f3(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return abs(i - j); +} + +double f4(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return 1./(i+j-1); +} diff --git a/2025.03.14/07Ex/init_f.h b/2025.03.14/07Ex/init_f.h new file mode 100644 index 0000000..691aace --- /dev/null +++ b/2025.03.14/07Ex/init_f.h @@ -0,0 +1,9 @@ +#ifndef INIT_F_H +#define INIT_F_H + +double f1(int n, int m, int i, int j); +double f2(int n, int m, int i, int j); +double f3(int n, int m, int i, int j); +double f4(int n, int m, int i, int j); + +#endif diff --git a/2025.03.14/07Ex/io_status.h b/2025.03.14/07Ex/io_status.h new file mode 100644 index 0000000..420a981 --- /dev/null +++ b/2025.03.14/07Ex/io_status.h @@ -0,0 +1,13 @@ +#ifndef IO_STATUS_H +#define IO_STATUS_H + +#define LEN 1234 + +typedef enum _io_status +{ + SUCCESS, + ERROR_OPEN, + ERROR_READ +} io_status; + +#endif diff --git a/2025.03.14/07Ex/main.c b/2025.03.14/07Ex/main.c new file mode 100644 index 0000000..e2269ba --- /dev/null +++ b/2025.03.14/07Ex/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 7; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t7_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf("New matrix:\n"); + print_matrix(a, n, m, p); + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/07Ex/solve.c b/2025.03.14/07Ex/solve.c new file mode 100644 index 0000000..b1f8e1f --- /dev/null +++ b/2025.03.14/07Ex/solve.c @@ -0,0 +1,32 @@ +#include "solve.h" +#include + +#define eps 1e-9 + +int compare(const double a, const double b) +{ + if (a - b > eps) return 1; + else if (b - a > eps) return -1; + return 0; +} + +double t7_solve(double *a, int n, int m) +{ + int i, j; + double cur = 0, maximum = 0; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (i == 0 || i == n-1 || j == 0 || j == m-1) + if (compare(fabs(a[i*m + j]), maximum) == 1) + maximum = fabs(a[i*m + j]); + + for (i = 1; i < n-1; i++) + for (j = 1; j < m-1; j++) + { + cur = (a[(i-1)*m + j] + a[(i+1)*m + j] + a[i*m + (j-1)] + a[i*m + (j+1)]) / 5; + if (compare(fabs(cur), maximum) == 1) maximum = fabs(cur); + a[i*m + j] = cur; + } + + return maximum; +} diff --git a/2025.03.14/07Ex/solve.h b/2025.03.14/07Ex/solve.h new file mode 100644 index 0000000..3fa374f --- /dev/null +++ b/2025.03.14/07Ex/solve.h @@ -0,0 +1,7 @@ +#ifndef SOLVE_H +#define SOLVE_H + +int compare(const double a, const double b); +double t7_solve(double *a, int n, int m); + +#endif diff --git a/2025.03.14/07Ex/t.txt b/2025.03.14/07Ex/t.txt new file mode 100644 index 0000000..65c2e7c --- /dev/null +++ b/2025.03.14/07Ex/t.txt @@ -0,0 +1,5 @@ +1 2 3 4 +5 6 7 8 +9 10 11 12 +13 14 15 16 +17 18 19 20 diff --git a/2025.03.14/08Ex/a.txt b/2025.03.14/08Ex/a.txt new file mode 100644 index 0000000..255e081 --- /dev/null +++ b/2025.03.14/08Ex/a.txt @@ -0,0 +1,3 @@ +1 2 3 4 +1 1 1 1 +2 2 2 2 diff --git a/2025.03.14/08Ex/array_io.c b/2025.03.14/08Ex/array_io.c new file mode 100644 index 0000000..6e56ecf --- /dev/null +++ b/2025.03.14/08Ex/array_io.c @@ -0,0 +1,40 @@ +#include +#include "array_io.h" + +io_status read_matrix(double *a, int n, int m, const char *name) +{ + int i, j; + FILE *fp; + if (!(fp = fopen(name, "r"))) return ERROR_OPEN; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (fscanf(fp, "%lf", a + i * m + j) != 1) + {fclose(fp); return ERROR_READ;} + fclose(fp); + return SUCCESS; +} + +void print_matrix(const double *a, int n, int m, int p) +{ + int np = (n > p ? p : n); + int mp = (m > p ? p : m); + int i, j; + + for (i = 0; i < np; i++) + { + for (j = 0; j < mp; j++) + printf(" %10.3e", a[i * m + j]); + printf("\n"); + } +} + +void init_matrix(double *a, int n, int m, int k) +{ + double (*q)(int, int, int, int); + double (*f[])(int, int, int, int) = {f1, f2, f3, f4}; + int i, j; + q = f[k-1]; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + a[i * m + j] = q(n, m, i+1, j+1); +} diff --git a/2025.03.14/08Ex/array_io.h b/2025.03.14/08Ex/array_io.h new file mode 100644 index 0000000..e312a84 --- /dev/null +++ b/2025.03.14/08Ex/array_io.h @@ -0,0 +1,11 @@ +#ifndef ARRAY_IO_H +#define ARRAY_IO_H + +#include "io_status.h" +#include "init_f.h" + +io_status read_matrix(double *a, int n, int m, const char *name); +void print_matrix(const double *a, int n, int m, int p); +void init_matrix(double *a, int n, int m, int k); + +#endif diff --git a/2025.03.14/08Ex/init_f.c b/2025.03.14/08Ex/init_f.c new file mode 100644 index 0000000..925afb5 --- /dev/null +++ b/2025.03.14/08Ex/init_f.c @@ -0,0 +1,30 @@ +#include "init_f.h" +#include + +#define MAX(n, m) (n < m ? m : n) + +double f1(int n, int m, int i, int j) +{ + return MAX(n, m) - MAX(i, j) + 1; +} + +double f2(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return MAX(i, j); +} + +double f3(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return abs(i - j); +} + +double f4(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return 1./(i+j-1); +} diff --git a/2025.03.14/08Ex/init_f.h b/2025.03.14/08Ex/init_f.h new file mode 100644 index 0000000..691aace --- /dev/null +++ b/2025.03.14/08Ex/init_f.h @@ -0,0 +1,9 @@ +#ifndef INIT_F_H +#define INIT_F_H + +double f1(int n, int m, int i, int j); +double f2(int n, int m, int i, int j); +double f3(int n, int m, int i, int j); +double f4(int n, int m, int i, int j); + +#endif diff --git a/2025.03.14/08Ex/io_status.h b/2025.03.14/08Ex/io_status.h new file mode 100644 index 0000000..420a981 --- /dev/null +++ b/2025.03.14/08Ex/io_status.h @@ -0,0 +1,13 @@ +#ifndef IO_STATUS_H +#define IO_STATUS_H + +#define LEN 1234 + +typedef enum _io_status +{ + SUCCESS, + ERROR_OPEN, + ERROR_READ +} io_status; + +#endif diff --git a/2025.03.14/08Ex/main.c b/2025.03.14/08Ex/main.c new file mode 100644 index 0000000..340c601 --- /dev/null +++ b/2025.03.14/08Ex/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 8; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t8_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf("New matrix:\n"); + print_matrix(a, n, m, p); + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/08Ex/solve.c b/2025.03.14/08Ex/solve.c new file mode 100644 index 0000000..9f8d226 --- /dev/null +++ b/2025.03.14/08Ex/solve.c @@ -0,0 +1,32 @@ +#include "solve.h" +#include + +#define eps 1e-9 + +int compare(const double a, const double b) +{ + if (a - b > eps) return 1; + else if (b - a > eps) return -1; + return 0; +} + +double t8_solve(double *a, int n, int m) +{ + int i, j; + double cur = 0, maximum = 0; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (i == 0 || i == n-1 || j == 0 || j == m-1) + if (compare(fabs(a[i*m + j]), maximum) == 1) + maximum = fabs(a[i*m + j]); + + for (i = n-2; i > 0; i--) + for (j = m-2; j > 0; j--) + { + cur = (a[(i+1)*m + j] + a[(i-1)*m + j] + a[i*m + (j-1)] + a[i*m + (j+1)]) / 5; + if (compare(fabs(cur), maximum) == 1) maximum = fabs(cur); + a[i*m + j] = cur; + } + + return maximum; +} diff --git a/2025.03.14/08Ex/solve.h b/2025.03.14/08Ex/solve.h new file mode 100644 index 0000000..abf6a0c --- /dev/null +++ b/2025.03.14/08Ex/solve.h @@ -0,0 +1,7 @@ +#ifndef SOLVE_H +#define SOLVE_H + +int compare(const double a, const double b); +double t8_solve(double *a, int n, int m); + +#endif diff --git a/2025.03.14/09Ex/a.txt b/2025.03.14/09Ex/a.txt new file mode 100644 index 0000000..255e081 --- /dev/null +++ b/2025.03.14/09Ex/a.txt @@ -0,0 +1,3 @@ +1 2 3 4 +1 1 1 1 +2 2 2 2 diff --git a/2025.03.14/09Ex/array_io.c b/2025.03.14/09Ex/array_io.c new file mode 100644 index 0000000..6e56ecf --- /dev/null +++ b/2025.03.14/09Ex/array_io.c @@ -0,0 +1,40 @@ +#include +#include "array_io.h" + +io_status read_matrix(double *a, int n, int m, const char *name) +{ + int i, j; + FILE *fp; + if (!(fp = fopen(name, "r"))) return ERROR_OPEN; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (fscanf(fp, "%lf", a + i * m + j) != 1) + {fclose(fp); return ERROR_READ;} + fclose(fp); + return SUCCESS; +} + +void print_matrix(const double *a, int n, int m, int p) +{ + int np = (n > p ? p : n); + int mp = (m > p ? p : m); + int i, j; + + for (i = 0; i < np; i++) + { + for (j = 0; j < mp; j++) + printf(" %10.3e", a[i * m + j]); + printf("\n"); + } +} + +void init_matrix(double *a, int n, int m, int k) +{ + double (*q)(int, int, int, int); + double (*f[])(int, int, int, int) = {f1, f2, f3, f4}; + int i, j; + q = f[k-1]; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + a[i * m + j] = q(n, m, i+1, j+1); +} diff --git a/2025.03.14/09Ex/array_io.h b/2025.03.14/09Ex/array_io.h new file mode 100644 index 0000000..e312a84 --- /dev/null +++ b/2025.03.14/09Ex/array_io.h @@ -0,0 +1,11 @@ +#ifndef ARRAY_IO_H +#define ARRAY_IO_H + +#include "io_status.h" +#include "init_f.h" + +io_status read_matrix(double *a, int n, int m, const char *name); +void print_matrix(const double *a, int n, int m, int p); +void init_matrix(double *a, int n, int m, int k); + +#endif diff --git a/2025.03.14/09Ex/init_f.c b/2025.03.14/09Ex/init_f.c new file mode 100644 index 0000000..925afb5 --- /dev/null +++ b/2025.03.14/09Ex/init_f.c @@ -0,0 +1,30 @@ +#include "init_f.h" +#include + +#define MAX(n, m) (n < m ? m : n) + +double f1(int n, int m, int i, int j) +{ + return MAX(n, m) - MAX(i, j) + 1; +} + +double f2(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return MAX(i, j); +} + +double f3(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return abs(i - j); +} + +double f4(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return 1./(i+j-1); +} diff --git a/2025.03.14/09Ex/init_f.h b/2025.03.14/09Ex/init_f.h new file mode 100644 index 0000000..691aace --- /dev/null +++ b/2025.03.14/09Ex/init_f.h @@ -0,0 +1,9 @@ +#ifndef INIT_F_H +#define INIT_F_H + +double f1(int n, int m, int i, int j); +double f2(int n, int m, int i, int j); +double f3(int n, int m, int i, int j); +double f4(int n, int m, int i, int j); + +#endif diff --git a/2025.03.14/09Ex/io_status.h b/2025.03.14/09Ex/io_status.h new file mode 100644 index 0000000..420a981 --- /dev/null +++ b/2025.03.14/09Ex/io_status.h @@ -0,0 +1,13 @@ +#ifndef IO_STATUS_H +#define IO_STATUS_H + +#define LEN 1234 + +typedef enum _io_status +{ + SUCCESS, + ERROR_OPEN, + ERROR_READ +} io_status; + +#endif diff --git a/2025.03.14/09Ex/main.c b/2025.03.14/09Ex/main.c new file mode 100644 index 0000000..061cbd8 --- /dev/null +++ b/2025.03.14/09Ex/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 9; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t9_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf("New matrix:\n"); + print_matrix(a, n, m, p); + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/09Ex/solve.c b/2025.03.14/09Ex/solve.c new file mode 100644 index 0000000..b572155 --- /dev/null +++ b/2025.03.14/09Ex/solve.c @@ -0,0 +1,32 @@ +#include "solve.h" +#include + +#define eps 1e-9 + +int compare(const double a, const double b) +{ + if (a - b > eps) return 1; + else if (b - a > eps) return -1; + return 0; +} + +double t9_solve(double *a, int n, int m) +{ + int i, j; + double cur = 0, maximum = 0; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (i == 0 || i == n-1 || j == 0 || j == m-1) + if (compare(fabs(a[i*m + j]), maximum) == 1) + maximum = fabs(a[i*m + j]); + + for (i = 1; i < n-1; i++) + for (j = m-2; j > 0; j--) + { + cur = (a[(i-1)*m + j] + a[(i+1)*m + j] + a[i*m + (j-1)] + a[i*m + (j+1)]) / 5; + if (compare(fabs(cur), maximum) == 1) maximum = fabs(cur); + a[i*m + j] = cur; + } + + return maximum; +} diff --git a/2025.03.14/09Ex/solve.h b/2025.03.14/09Ex/solve.h new file mode 100644 index 0000000..ccb9552 --- /dev/null +++ b/2025.03.14/09Ex/solve.h @@ -0,0 +1,7 @@ +#ifndef SOLVE_H +#define SOLVE_H + +int compare(const double a, const double b); +double t9_solve(double *a, int n, int m); + +#endif diff --git a/2025.03.14/10Ex/a.txt b/2025.03.14/10Ex/a.txt new file mode 100644 index 0000000..255e081 --- /dev/null +++ b/2025.03.14/10Ex/a.txt @@ -0,0 +1,3 @@ +1 2 3 4 +1 1 1 1 +2 2 2 2 diff --git a/2025.03.14/10Ex/array_io.c b/2025.03.14/10Ex/array_io.c new file mode 100644 index 0000000..6e56ecf --- /dev/null +++ b/2025.03.14/10Ex/array_io.c @@ -0,0 +1,40 @@ +#include +#include "array_io.h" + +io_status read_matrix(double *a, int n, int m, const char *name) +{ + int i, j; + FILE *fp; + if (!(fp = fopen(name, "r"))) return ERROR_OPEN; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (fscanf(fp, "%lf", a + i * m + j) != 1) + {fclose(fp); return ERROR_READ;} + fclose(fp); + return SUCCESS; +} + +void print_matrix(const double *a, int n, int m, int p) +{ + int np = (n > p ? p : n); + int mp = (m > p ? p : m); + int i, j; + + for (i = 0; i < np; i++) + { + for (j = 0; j < mp; j++) + printf(" %10.3e", a[i * m + j]); + printf("\n"); + } +} + +void init_matrix(double *a, int n, int m, int k) +{ + double (*q)(int, int, int, int); + double (*f[])(int, int, int, int) = {f1, f2, f3, f4}; + int i, j; + q = f[k-1]; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + a[i * m + j] = q(n, m, i+1, j+1); +} diff --git a/2025.03.14/10Ex/array_io.h b/2025.03.14/10Ex/array_io.h new file mode 100644 index 0000000..e312a84 --- /dev/null +++ b/2025.03.14/10Ex/array_io.h @@ -0,0 +1,11 @@ +#ifndef ARRAY_IO_H +#define ARRAY_IO_H + +#include "io_status.h" +#include "init_f.h" + +io_status read_matrix(double *a, int n, int m, const char *name); +void print_matrix(const double *a, int n, int m, int p); +void init_matrix(double *a, int n, int m, int k); + +#endif diff --git a/2025.03.14/10Ex/init_f.c b/2025.03.14/10Ex/init_f.c new file mode 100644 index 0000000..925afb5 --- /dev/null +++ b/2025.03.14/10Ex/init_f.c @@ -0,0 +1,30 @@ +#include "init_f.h" +#include + +#define MAX(n, m) (n < m ? m : n) + +double f1(int n, int m, int i, int j) +{ + return MAX(n, m) - MAX(i, j) + 1; +} + +double f2(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return MAX(i, j); +} + +double f3(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return abs(i - j); +} + +double f4(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return 1./(i+j-1); +} diff --git a/2025.03.14/10Ex/init_f.h b/2025.03.14/10Ex/init_f.h new file mode 100644 index 0000000..691aace --- /dev/null +++ b/2025.03.14/10Ex/init_f.h @@ -0,0 +1,9 @@ +#ifndef INIT_F_H +#define INIT_F_H + +double f1(int n, int m, int i, int j); +double f2(int n, int m, int i, int j); +double f3(int n, int m, int i, int j); +double f4(int n, int m, int i, int j); + +#endif diff --git a/2025.03.14/10Ex/io_status.h b/2025.03.14/10Ex/io_status.h new file mode 100644 index 0000000..420a981 --- /dev/null +++ b/2025.03.14/10Ex/io_status.h @@ -0,0 +1,13 @@ +#ifndef IO_STATUS_H +#define IO_STATUS_H + +#define LEN 1234 + +typedef enum _io_status +{ + SUCCESS, + ERROR_OPEN, + ERROR_READ +} io_status; + +#endif diff --git a/2025.03.14/10Ex/main.c b/2025.03.14/10Ex/main.c new file mode 100644 index 0000000..0c29030 --- /dev/null +++ b/2025.03.14/10Ex/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 10; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t10_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf("New matrix:\n"); + print_matrix(a, n, m, p); + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/10Ex/solve.c b/2025.03.14/10Ex/solve.c new file mode 100644 index 0000000..2a9d48c --- /dev/null +++ b/2025.03.14/10Ex/solve.c @@ -0,0 +1,32 @@ +#include "solve.h" +#include + +#define eps 1e-9 + +int compare(const double a, const double b) +{ + if (a - b > eps) return 1; + else if (b - a > eps) return -1; + return 0; +} + +double t10_solve(double *a, int n, int m) +{ + int i, j; + double cur = 0, maximum = 0; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (i == 0 || i == n-1 || j == 0 || j == m-1) + if (compare(fabs(a[i*m + j]), maximum) == 1) + maximum = fabs(a[i*m + j]); + + for (i = n-2; i > 0; i--) + for (j = 1; j < m-1; j++) + { + cur = (a[(i+1)*m + j] + a[(i-1)*m + j] + a[i*m + (j-1)] + a[i*m + (j+1)]) / 5; + if (compare(fabs(cur), maximum) == 1) maximum = fabs(cur); + a[i*m + j] = cur; + } + + return maximum; +} diff --git a/2025.03.14/10Ex/solve.h b/2025.03.14/10Ex/solve.h new file mode 100644 index 0000000..8ae0fc3 --- /dev/null +++ b/2025.03.14/10Ex/solve.h @@ -0,0 +1,7 @@ +#ifndef SOLVE_H +#define SOLVE_H + +int compare(const double a, const double b); +double t10_solve(double *a, int n, int m); + +#endif diff --git a/2025.03.14/11Ex/a.txt b/2025.03.14/11Ex/a.txt new file mode 100644 index 0000000..bf87c21 --- /dev/null +++ b/2025.03.14/11Ex/a.txt @@ -0,0 +1,3 @@ +1 1 1 1 +1 2 3 4 +2 2 2 2 diff --git a/2025.03.14/11Ex/array_io.c b/2025.03.14/11Ex/array_io.c new file mode 100644 index 0000000..6e56ecf --- /dev/null +++ b/2025.03.14/11Ex/array_io.c @@ -0,0 +1,40 @@ +#include +#include "array_io.h" + +io_status read_matrix(double *a, int n, int m, const char *name) +{ + int i, j; + FILE *fp; + if (!(fp = fopen(name, "r"))) return ERROR_OPEN; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (fscanf(fp, "%lf", a + i * m + j) != 1) + {fclose(fp); return ERROR_READ;} + fclose(fp); + return SUCCESS; +} + +void print_matrix(const double *a, int n, int m, int p) +{ + int np = (n > p ? p : n); + int mp = (m > p ? p : m); + int i, j; + + for (i = 0; i < np; i++) + { + for (j = 0; j < mp; j++) + printf(" %10.3e", a[i * m + j]); + printf("\n"); + } +} + +void init_matrix(double *a, int n, int m, int k) +{ + double (*q)(int, int, int, int); + double (*f[])(int, int, int, int) = {f1, f2, f3, f4}; + int i, j; + q = f[k-1]; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + a[i * m + j] = q(n, m, i+1, j+1); +} diff --git a/2025.03.14/11Ex/array_io.h b/2025.03.14/11Ex/array_io.h new file mode 100644 index 0000000..e312a84 --- /dev/null +++ b/2025.03.14/11Ex/array_io.h @@ -0,0 +1,11 @@ +#ifndef ARRAY_IO_H +#define ARRAY_IO_H + +#include "io_status.h" +#include "init_f.h" + +io_status read_matrix(double *a, int n, int m, const char *name); +void print_matrix(const double *a, int n, int m, int p); +void init_matrix(double *a, int n, int m, int k); + +#endif diff --git a/2025.03.14/11Ex/init_f.c b/2025.03.14/11Ex/init_f.c new file mode 100644 index 0000000..925afb5 --- /dev/null +++ b/2025.03.14/11Ex/init_f.c @@ -0,0 +1,30 @@ +#include "init_f.h" +#include + +#define MAX(n, m) (n < m ? m : n) + +double f1(int n, int m, int i, int j) +{ + return MAX(n, m) - MAX(i, j) + 1; +} + +double f2(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return MAX(i, j); +} + +double f3(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return abs(i - j); +} + +double f4(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return 1./(i+j-1); +} diff --git a/2025.03.14/11Ex/init_f.h b/2025.03.14/11Ex/init_f.h new file mode 100644 index 0000000..691aace --- /dev/null +++ b/2025.03.14/11Ex/init_f.h @@ -0,0 +1,9 @@ +#ifndef INIT_F_H +#define INIT_F_H + +double f1(int n, int m, int i, int j); +double f2(int n, int m, int i, int j); +double f3(int n, int m, int i, int j); +double f4(int n, int m, int i, int j); + +#endif diff --git a/2025.03.14/11Ex/io_status.h b/2025.03.14/11Ex/io_status.h new file mode 100644 index 0000000..420a981 --- /dev/null +++ b/2025.03.14/11Ex/io_status.h @@ -0,0 +1,13 @@ +#ifndef IO_STATUS_H +#define IO_STATUS_H + +#define LEN 1234 + +typedef enum _io_status +{ + SUCCESS, + ERROR_OPEN, + ERROR_READ +} io_status; + +#endif diff --git a/2025.03.14/11Ex/main.c b/2025.03.14/11Ex/main.c new file mode 100644 index 0000000..3099d8d --- /dev/null +++ b/2025.03.14/11Ex/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 11; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t11_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf("New matrix:\n"); + print_matrix(a, n, m, p); + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/11Ex/solve.c b/2025.03.14/11Ex/solve.c new file mode 100644 index 0000000..39d263e --- /dev/null +++ b/2025.03.14/11Ex/solve.c @@ -0,0 +1,41 @@ +#include "solve.h" +#include + +#define eps 1e-9 + +int compare(const double a, const double b) +{ + if (a - b > eps) return 1; + else if (b - a > eps) return -1; + return 0; +} + +double t11_solve(double *a, int n, int m) +{ + int i, j, max_i = 0, max_j = 0; + double temp = 0, maximum = 0; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (compare(fabs(a[i*m + j]), maximum) == 1) + { + maximum = fabs(a[i*m + j]); + max_i = i; + max_j = j; + } + if (max_i != 0) + for (j = 0; j < m; j++) + { + temp = a[max_i*m+j]; + a[max_i*m+j] = a[j]; + a[j] = temp; + } + if (max_j != 0) + for (i = 0; i < n; i++) + { + temp = a[i*m + max_j]; + a[i*m + max_j] = a[i*m]; + a[i*m] = temp; + } + + return maximum; +} diff --git a/2025.03.14/11Ex/solve.h b/2025.03.14/11Ex/solve.h new file mode 100644 index 0000000..f219349 --- /dev/null +++ b/2025.03.14/11Ex/solve.h @@ -0,0 +1,7 @@ +#ifndef SOLVE_H +#define SOLVE_H + +int compare(const double a, const double b); +double t11_solve(double *a, int n, int m); + +#endif diff --git a/2025.03.14/1Ex/Makefile b/2025.03.14/1Ex/Makefile deleted file mode 100644 index 25150b6..0000000 --- a/2025.03.14/1Ex/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -FLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused -Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 -Wwrite-strings -Wcast-align -Wno-long-long -std=gnu99 -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs -O3 - -a01.exe: main.o array_io.o solve.o init_f.o - gcc main.o solve.o array_io.o init_f.o -o a01.exe -lssp - -main.o: main.c - gcc $(CFLAGS) -c main.c - -solve.o: solve.c - gcc $(FLAGS) -c solve.c - -array_io.o: array_io.c - gcc $(CFLAGS) -c array_io.c - -init_f.o: init_f.c - gcc $(CFLAGS) -c init_f.c - -clean: - del *.o *.exe diff --git a/2025.03.14/2Ex/Makefile b/2025.03.14/2Ex/Makefile deleted file mode 100644 index f7c9fe2..0000000 --- a/2025.03.14/2Ex/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -FLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused -Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 -Wwrite-strings -Wcast-align -Wno-long-long -std=gnu99 -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs -O3 - -a02.exe: main.o array_io.o solve.o init_f.o - gcc main.o solve.o array_io.o init_f.o -o a02.exe -lssp - -main.o: main.c - gcc $(CFLAGS) -c main.c - -solve.o: solve.c - gcc $(FLAGS) -c solve.c - -array_io.o: array_io.c - gcc $(CFLAGS) -c array_io.c - -init_f.o: init_f.c - gcc $(CFLAGS) -c init_f.c - -clean: - del *.o *.exe diff --git a/2025.03.14/2Ex/test_cases.json b/2025.03.14/2Ex/test_cases.json deleted file mode 100644 index b2e015c..0000000 --- a/2025.03.14/2Ex/test_cases.json +++ /dev/null @@ -1,123 +0,0 @@ -{ - "exe": "a08.exe", - "filename": "matrix.txt", - "tests": [ - { - "name": "File Matrix Test", - "i": 1, - "j": 2, - "g": 2, - "k": 0, - "p": 5, - "matrix": "1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n17 18 19 20" - }, - { - "name": "Basic Addition", - "i": 1, - "j": 2, - "g": 2, - "n": 3, - "m": 3, - "p": 3, - "k": 0, - "matrix": "1 2 3\n4 5 6\n7 8 9" - }, - { - "name": "Negative Gamma", - "i": 1, - "j": 3, - "g": -1, - "n": 3, - "m": 3, - "p": 3, - "k": 0, - "matrix": "1 2 3\n4 5 6\n7 8 9" - }, - { - "name": "Large 1000x1000 Matrix", - "i": 500, - "j": 999, - "g": 1.5, - "n": 1000, - "m": 1000, - "k": 1 - }, - { - "name": "Floating Point Values", - "i": 1, - "j": 3, - "g": 0.5, - "n": 3, - "m": 3, - "p": 3, - "k": 0, - "matrix": "1.1 2.2 3.3\n4.4 5.5 6.6\n7.7 8.8 9.9" - }, - { - "name": "Negative Values", - "i": 1, - "j": 2, - "g": -2, - "n": 3, - "m": 3, - "p": 3, - "k": 0, - "matrix": "-1 -2 -3\n-4 -5 -6\n-7 -8 -9" - }, - { - "name": "Adding a Row to Itself (Should Double)", - "i": 2, - "j": 2, - "g": 1, - "n": 3, - "m": 3, - "p": 3, - "k": 0, - "matrix": "1 2 3\n4 5 6\n7 8 9" - }, - { - "name": "Adding Row with Gamma = 0 (No Change)", - "i": 1, - "j": 3, - "g": 0, - "n": 3, - "m": 3, - "p": 3, - "k": 0, - "matrix": "1 2 3\n4 5 6\n7 8 9" - }, - { - "name": "Identity Matrix Transformation", - "i": 2, - "j": 3, - "g": 1, - "n": 3, - "m": 3, - "p": 3, - "k": 0, - "matrix": "1 0 0\n0 1 0\n0 0 1" - }, - { - "name": "All Zeroes", - "i": 1, - "j": 2, - "g": 5, - "n": 4, - "m": 4, - "p": 4, - "k": 0, - "matrix": "0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0" - }, - { - "name": "Different Row Sizes", - "i": 2, - "j": 3, - "g": 3, - "n": 4, - "m": 5, - "p": 5, - "k": 0, - "matrix": "10 20 30 40 50\n60 70 80 90 100\n110 120 130 140 150\n160 170 180 190 200" - } - ] -} diff --git a/2025.03.14/2Ex/test_runner.py b/2025.03.14/2Ex/test_runner.py deleted file mode 100644 index 375ff4e..0000000 --- a/2025.03.14/2Ex/test_runner.py +++ /dev/null @@ -1,176 +0,0 @@ -import json -import subprocess -import os -import time -import platform -import re -import signal -from colorama import Fore, Style, init - -# Enable color support in Windows -init(autoreset=True) - -def color_text(text, color): - """Returns colored text""" - return color + text + Style.RESET_ALL - -def cleanup_and_exit(): - """Handles cleanup on Ctrl+C or forced exit""" - print(color_text("\n[ABORT] Operation interrupted. Cleaning up...", Fore.RED)) - run_command("make clean") - exit(1) - -# Register Ctrl+C handler -signal.signal(signal.SIGINT, lambda sig, frame: cleanup_and_exit()) - -class TestCase: - """Represents a single test case""" - def __init__(self, i, j, g, k, matrix=None, n=None, m=None, p=None, debug=False, name=None): - self.i = i - self.j = j - self.g = g - self.k = k - self.matrix = matrix - self.n = n - self.m = m - self.p = p - self.debug = debug - self.name = name if name else f"Test k={k}, n={n if n else 'auto'}, m={m if m else 'auto'}, p={p if p else 'auto'}" - - # Compute `n` if missing and `k == 0` - if self.k == 0 and self.matrix: - if not self.n: - self.n = len(self.matrix.strip().split("\n")) - if not self.m: - self.m = len(self.matrix.strip().split("\n")[0].split()) - - # Compute `p` - self.p = self.p if self.p else self.n - - def validate_inputs(self): - """Ensures input values are valid""" - if self.k < 0 or (self.k == 0 and not self.matrix): - print(color_text(f"[ERROR] Invalid test parameters: {self.name}", Fore.RED)) - return False - return True - -class TestSuite: - """Handles loading and running test cases""" - def __init__(self, config_file): - self.config = self.load_config(config_file) - self.exe = self.config["exe"] - self.filename = self.config["filename"] - self.tests = [TestCase(**test) for test in self.config["tests"]] - - @staticmethod - def load_config(filename): - """Loads test cases from JSON""" - with open(filename, "r", encoding="utf-8") as f: - return json.load(f) - -def run_command(cmd, exit_on_error=False): - """Runs a shell command and handles errors""" - try: - result = subprocess.run(cmd, shell=True, capture_output=True, text=True) - return result - except subprocess.CalledProcessError as e: - print(color_text(f"[ERROR] Command failed: {cmd}", Fore.RED)) - print(e.stderr) - if exit_on_error: - exit(1) - return None - -def wait_for_executable(exe): - """Waits for the executable file to appear after compilation""" - print(color_text(f"[WAIT] Waiting for {exe} to be compiled...", Fore.YELLOW)) - while not os.path.exists(exe): - time.sleep(0.1) # Reduce CPU usage - print(color_text(f"[READY] {exe} compiled successfully.", Fore.GREEN)) - -def format_matrix(matrix): - """Formats a matrix to match `printf("%10.3e")` output""" - formatted = [] - for row in matrix.strip().split("\n"): - formatted.append(" ".join(f"{float(num):10.3e}" for num in row.split())) - return "\n".join(formatted) - -def result_matrix_output(output): - parts = output.split("Result matrix:\n") - if len(parts) > 1: - matrix_lines = parts[1].strip().split("\n") - return format_matrix("\n".join(matrix_lines[:-1])) - return "" - -def initial_matrix_output(output): - parts = output.split("Initial matrix:\n") - if len(parts) > 1: - parts = parts[1].split("Result") - matrix_lines = parts[0].strip().split("\n") - return format_matrix("\n".join(matrix_lines)) - return "" - -def ep1_matrix(matrix, i, j, g): - rows = matrix.strip().split("\n") - ep1 = [[float(num) for num in row.split()] for row in rows] - for k in range(len(ep1[0])): ep1[j][k] += ep1[i][k] * g - return "\n".join(" ".join(f"{num:10.3e}" for num in row) for row in ep1) - -def run_test(test_suite, test): - """Runs the program and checks its result""" - if not test.validate_inputs(): - return - - exe, filename = test_suite.exe, test_suite.filename - - # If matrix is given, write it to the file - if test.k == 0 and test.matrix: - with open(filename, "w", encoding="utf-8") as f: - f.write(format_matrix(test.matrix.strip()) + "\n") - - cmd = [exe, str(test.i), str(test.j), str(test.g), str(test.n), str(test.m), str(test.p), str(test.k)] - if test.k == 0: - cmd.append(filename) - - # Run the program - result = run_command(cmd) - - # Extract both initial and result matrices - initial_matrix = initial_matrix_output(result.stdout) - result_matrix = result_matrix_output(result.stdout) - - expected_transposed = ep1_matrix(initial_matrix, test.i-1, test.j-1, test.g) - - if result_matrix.strip() != expected_transposed.strip(): - print(color_text(f"[FAIL] Test '{test.name}' matrix mismatch.", Fore.RED)) - print(f"Expected:\n{expected_transposed}") - print(f"Got:\n{result_matrix}") - return - - print(color_text(f"[PASS] Test '{test.name}' passed.", Fore.GREEN)) - - if test.k == 0: - # Cleanup test file - try: - os.remove(filename) - except (FileNotFoundError, PermissionError): - print(color_text(f"[WARNING] Could not delete {filename}, Windows may be locking it.", Fore.RED)) - - -def main(): - print(color_text("[CLEAN] Cleaning project...", Fore.BLUE)) - run_command("make clean", exit_on_error=True) - - print(color_text("[BUILD] Compiling project...", Fore.BLUE)) - run_command("make", exit_on_error=True) - - test_suite = TestSuite("test_cases.json") - wait_for_executable(test_suite.exe) - - for test in test_suite.tests: - run_test(test_suite, test) - - print(color_text("[CLEAN] Final cleanup...", Fore.BLUE)) - run_command("make clean") - -if __name__ == "__main__": - main() diff --git a/2025.03.14/3Ex/Makefile b/2025.03.14/3Ex/Makefile deleted file mode 100644 index 13a2d7b..0000000 --- a/2025.03.14/3Ex/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -FLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused -Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 -Wwrite-strings -Wcast-align -Wno-long-long -std=gnu99 -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs -O3 - -a03.exe: main.o array_io.o solve.o init_f.o - gcc main.o solve.o array_io.o init_f.o -o a03.exe -lssp - -main.o: main.c - gcc $(CFLAGS) -c main.c - -solve.o: solve.c - gcc $(FLAGS) -c solve.c - -array_io.o: array_io.c - gcc $(CFLAGS) -c array_io.c - -init_f.o: init_f.c - gcc $(CFLAGS) -c init_f.c - -clean: - del *.o *.exe diff --git a/2025.03.14/4Ex/Makefile b/2025.03.14/4Ex/Makefile deleted file mode 100644 index f82bcf8..0000000 --- a/2025.03.14/4Ex/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -FLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused -Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 -Wwrite-strings -Wcast-align -Wno-long-long -std=gnu99 -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs -O3 - -a04.exe: main.o array_io.o solve.o init_f.o - gcc main.o solve.o array_io.o init_f.o -o a04.exe -lssp - -main.o: main.c - gcc $(CFLAGS) -c main.c - -solve.o: solve.c - gcc $(FLAGS) -c solve.c - -array_io.o: array_io.c - gcc $(CFLAGS) -c array_io.c - -init_f.o: init_f.c - gcc $(CFLAGS) -c init_f.c - -clean: - del *.o *.exe diff --git a/2025.03.14/5Ex/init_f.c b/2025.03.14/5Ex/init_f.c deleted file mode 100644 index cf325c3..0000000 --- a/2025.03.14/5Ex/init_f.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "init_f.h" -#include - -#define MAX(n, m) (n < m ? m : n) - -double f1(int n, int m, int i, int j) -{ - return MAX(n, m) - MAX(i, j) + 1; -} - -double f2(int n, int m, int i, int j) -{ - (void)n; - (void)m; - return MAX(i, j); -} - -double f3(int n, int m, int i, int j) -{ - (void)n; - (void)m; - return abs(i - j); -} - -double f4(int n, int m, int i, int j) -{ - (void)n; - (void)m; - return 1./(i+j-1); -} diff --git a/2025.03.14/5Ex/io_status.h b/2025.03.14/5Ex/io_status.h deleted file mode 100644 index a51376d..0000000 --- a/2025.03.14/5Ex/io_status.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef IO_STATUS_H -#define IO_STATUS_H - -#define LEN 1234 - -typedef enum _io_status -{ - SUCCESS, - ERROR_OPEN, - ERROR_READ, - ERROR_MEM -} io_status; - -#endif diff --git a/2025.03.14/Linux/a01.c b/2025.03.14/Linux/a01.c new file mode 100644 index 0000000..0631900 --- /dev/null +++ b/2025.03.14/Linux/a01.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 1; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t1_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/Linux/a02.c b/2025.03.14/Linux/a02.c new file mode 100644 index 0000000..d53bed3 --- /dev/null +++ b/2025.03.14/Linux/a02.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 2; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t2_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/Linux/a03.c b/2025.03.14/Linux/a03.c new file mode 100644 index 0000000..785fa2a --- /dev/null +++ b/2025.03.14/Linux/a03.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k_a [filename_a] k_b [filename_b] k_x [filename_x] */ +int main(int argc, char *argv[]) +{ + double t, res, *a, *b, *x; + int n, m, p, k_a, k_b, k_x, task = 3; + char *name_a = 0, *name_b = 0, *name_x = 0; + + if (!((argc >= 7 && argc <= 10) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k_a) == 1 && + (k_a >= 0 && k_a <= 4) && + (!(k_a == 0 && argc == 7)) && + ((k_a == 0 && sscanf(argv[6], "%d", &k_b) == 1) || + (k_a != 0 && sscanf(argv[5], "%d", &k_b) == 1)) && + (k_b >= 0 && k_b <= 4) && + (!(k_b == 0 && ((argc <= 7) || (k_a == 0 && argc <= 8)))) && + ((k_a == 0 && k_b == 0 && sscanf(argv[8], "%d", &k_x) == 1) || + (k_a != 0 && k_b != 0 && sscanf(argv[6], "%d", &k_x) == 1) || + (sscanf(argv[7], "%d", &k_x) == 1)) && + (k_x >= 0 && k_x <= 4) && + (!(k_x == 0 && ((k_a == 0 && k_b == 0 && argc != 10) || + (k_a != 0 && k_b != 0 && argc != 8) || + (k_a != k_b && argc != 9)))))) + { + printf("Usage: %s n m p k_a [filename_a] k_b [filename_b] k_x [filename_x]\n", argv[0]); + return 1; + } + + if (argc != 7) + { + int i_b = 6; + if (k_a == 0) { name_a = argv[5]; i_b++; } + if (k_b == 0) { name_b = argv[i_b]; i_b+=2; } + else i_b++; + if (k_x == 0) name_x = argv[i_b]; + } + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + b = (double *)malloc(n * sizeof(double)); + if (!b) + { + free(a); + printf("Not enough memory\n"); + return 2; + } + + x = (double *)malloc(m * sizeof(double)); + if (!x) + { + free(a); + free(b); + printf("Not enough memory\n"); + return 2; + } + + if (name_a) + { /* Читаем матрицу A из файла */ + io_status ret; + ret = read_matrix(a, n, m, name_a); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_a); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_a); + break; + } + free(a); + free(b); + free(x); + return 3; + } while (0); + } + else init_matrix(a, n, m, k_a); + + if (name_b) + { /* Читаем матрицу B из файла */ + io_status ret; + ret = read_matrix(b, n, 1, name_b); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_b); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_b); + break; + } + free(a); + free(b); + free(x); + return 3; + } while (0); + } + else init_matrix(b, n, 1, k_b); + + if (name_x) + { /* Читаем матрицу X из файла */ + io_status ret; + ret = read_matrix(x, m, 1, name_x); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_x); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_x); + break; + } + free(a); + free(b); + free(x); + return 3; + } while (0); + } + else init_matrix(x, m, 1, k_x); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + printf("Initial vector b:\n"); + print_matrix(b, n, 1, p); + printf("Initial vector x:\n"); + print_matrix(x, m, 1, p); + + t = clock(); + res = t3_solve(a, x, b, m, n); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + free(b); + free(x); + + return 0; +} diff --git a/2025.03.14/Linux/a04.c b/2025.03.14/Linux/a04.c new file mode 100644 index 0000000..4118184 --- /dev/null +++ b/2025.03.14/Linux/a04.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k_a [filename_a] k_b [filename_b] k_x [filename_x] */ +int main(int argc, char *argv[]) +{ + double t, res, *a, *b, *x; + int n, m, p, k_a, k_b, k_x, task = 4; + char *name_a = 0, *name_b = 0, *name_x = 0; + + if (!((argc >= 7 && argc <= 10) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k_a) == 1 && + (k_a >= 0 && k_a <= 4) && + (!(k_a == 0 && argc == 7)) && + ((k_a == 0 && sscanf(argv[6], "%d", &k_b) == 1) || + (k_a != 0 && sscanf(argv[5], "%d", &k_b) == 1)) && + (k_b >= 0 && k_b <= 4) && + (!(k_b == 0 && ((argc <= 7) || (k_a == 0 && argc <= 8)))) && + ((k_a == 0 && k_b == 0 && sscanf(argv[8], "%d", &k_x) == 1) || + (k_a != 0 && k_b != 0 && sscanf(argv[6], "%d", &k_x) == 1) || + (sscanf(argv[7], "%d", &k_x) == 1)) && + (k_x >= 0 && k_x <= 4) && + (!(k_x == 0 && ((k_a == 0 && k_b == 0 && argc != 10) || + (k_a != 0 && k_b != 0 && argc != 8) || + (k_a != k_b && argc != 9)))))) + { + printf("Usage: %s n m p k_a [filename_a] k_b [filename_b] k_x [filename_x]\n", argv[0]); + return 1; + } + + if (argc != 7) + { + int i_b = 6; + if (k_a == 0) { name_a = argv[5]; i_b++; } + if (k_b == 0) { name_b = argv[i_b]; i_b+=2; } + else i_b++; + if (k_x == 0) name_x = argv[i_b]; + } + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + b = (double *)malloc(n * sizeof(double)); + if (!b) + { + free(a); + printf("Not enough memory\n"); + return 2; + } + + x = (double *)malloc(m * sizeof(double)); + if (!x) + { + free(a); + free(b); + printf("Not enough memory\n"); + return 2; + } + + if (name_a) + { /* Читаем матрицу A из файла */ + io_status ret; + ret = read_matrix(a, n, m, name_a); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_a); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_a); + break; + } + free(a); + free(b); + free(x); + return 3; + } while (0); + } + else init_matrix(a, n, m, k_a); + + if (name_b) + { /* Читаем матрицу B из файла */ + io_status ret; + ret = read_matrix(b, n, 1, name_b); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_b); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_b); + break; + } + free(a); + free(b); + free(x); + return 3; + } while (0); + } + else init_matrix(b, n, 1, k_b); + + if (name_x) + { /* Читаем матрицу X из файла */ + io_status ret; + ret = read_matrix(x, m, 1, name_x); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_x); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_x); + break; + } + free(a); + free(b); + free(x); + return 3; + } while (0); + } + else init_matrix(x, m, 1, k_x); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + printf("Initial vector b:\n"); + print_matrix(b, n, 1, p); + printf("Initial vector x:\n"); + print_matrix(x, m, 1, p); + + t = clock(); + res = t4_solve(a, x, b, m, n); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + free(b); + free(x); + + return 0; +} diff --git a/2025.03.14/Linux/a05.c b/2025.03.14/Linux/a05.c new file mode 100644 index 0000000..814b3ff --- /dev/null +++ b/2025.03.14/Linux/a05.c @@ -0,0 +1,110 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k_a [filename_a] k_b [filename_b] */ +int main(int argc, char *argv[]) +{ + double t, res, *a, *b; + int n, m, p, k_a, k_b, task = 5; + char *name_a = 0, *name_b = 0; + if (!((argc == 6 || argc == 7 || argc == 8) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k_a) == 1 && + (k_a >= 0 && k_a <= 4) && + (!(k_a == 0 && argc == 6)) && + ((k_a == 0 && sscanf(argv[6], "%d", &k_b) == 1) || + (k_a != 0 && sscanf(argv[5], "%d", &k_b) == 1)) && + (k_b >= 0 && k_b <= 4) && + (!(k_b == 0 && argc == 6)) && + (!((k_a == 0 && k_b == 0) && argc != 8)))) + { + printf("Usage: %s n m p k_a [filename_a] k_b [filename_b]\n", argv[0]); + return 1; + } + if (argc != 6) + { + int i_b = 6; + if (k_a == 0) {name_a = argv[5];i_b++;} + if (k_b == 0) name_b = argv[i_b]; + } + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + b = (double *)malloc(m * n * sizeof(double)); + if (!b) + { + free(a); + printf("Not enough memory\n"); + return 2; + } + + if (name_a) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name_a); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_a); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_a); + break; + } + free(a); + free(b); + return 3; + } while (0); + } else init_matrix(a, n, m, k_a); + + if (name_b) + { + io_status ret; + ret = read_matrix(b, m, n, name_b); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_b); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_b); + break; + } + free(a); + free(b); + return 3; + } while (0); + } else init_matrix(b, m, n, k_b); + + printf("Matrix A:\n"); + print_matrix(a, n, m, p); + printf("Matrix B:\n"); + print_matrix(b, m, n, p); + + t = clock(); + res = t5_solve(a, b, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + free(b); + + return 0; +} diff --git a/2025.03.14/Linux/a06.c b/2025.03.14/Linux/a06.c new file mode 100644 index 0000000..c97210d --- /dev/null +++ b/2025.03.14/Linux/a06.c @@ -0,0 +1,110 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k_a [filename_a] k_b [filename_b] */ +int main(int argc, char *argv[]) +{ + double t, res, *a, *b; + int n, m, p, k_a, k_b, task = 6; + char *name_a = 0, *name_b = 0; + if (!((argc == 6 || argc == 7 || argc == 8) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k_a) == 1 && + (k_a >= 0 && k_a <= 4) && + (!(k_a == 0 && argc == 6)) && + ((k_a == 0 && sscanf(argv[6], "%d", &k_b) == 1) || + (k_a != 0 && sscanf(argv[5], "%d", &k_b) == 1)) && + (k_b >= 0 && k_b <= 4) && + (!(k_b == 0 && argc == 6)) && + (!((k_a == 0 && k_b == 0) && argc != 8)))) + { + printf("Usage: %s n m p k_a [filename_a] k_b [filename_b]\n", argv[0]); + return 1; + } + if (argc != 6) + { + int i_b = 6; + if (k_a == 0) {name_a = argv[5];i_b++;} + if (k_b == 0) name_b = argv[i_b]; + } + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + b = (double *)malloc(m * n * sizeof(double)); + if (!b) + { + free(a); + printf("Not enough memory\n"); + return 2; + } + + if (name_a) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name_a); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_a); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_a); + break; + } + free(a); + free(b); + return 3; + } while (0); + } else init_matrix(a, n, m, k_a); + + if (name_b) + { + io_status ret; + ret = read_matrix(b, m, n, name_b); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name_b); + break; + case ERROR_READ: + printf("Cannot read %s\n", name_b); + break; + } + free(a); + free(b); + return 3; + } while (0); + } else init_matrix(b, m, n, k_b); + + printf("Matrix A:\n"); + print_matrix(a, n, m, p); + printf("Matrix B:\n"); + print_matrix(b, m, n, p); + + t = clock(); + res = t6_solve(a, b, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + free(b); + + return 0; +} diff --git a/2025.03.14/Linux/a07.c b/2025.03.14/Linux/a07.c new file mode 100644 index 0000000..e2269ba --- /dev/null +++ b/2025.03.14/Linux/a07.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 7; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t7_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf("New matrix:\n"); + print_matrix(a, n, m, p); + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/Linux/a08.c b/2025.03.14/Linux/a08.c new file mode 100644 index 0000000..340c601 --- /dev/null +++ b/2025.03.14/Linux/a08.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 8; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t8_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf("New matrix:\n"); + print_matrix(a, n, m, p); + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/Linux/a09.c b/2025.03.14/Linux/a09.c new file mode 100644 index 0000000..061cbd8 --- /dev/null +++ b/2025.03.14/Linux/a09.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 9; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t9_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf("New matrix:\n"); + print_matrix(a, n, m, p); + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/Linux/a10.c b/2025.03.14/Linux/a10.c new file mode 100644 index 0000000..0c29030 --- /dev/null +++ b/2025.03.14/Linux/a10.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 10; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t10_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf("New matrix:\n"); + print_matrix(a, n, m, p); + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/Linux/a11.c b/2025.03.14/Linux/a11.c new file mode 100644 index 0000000..3099d8d --- /dev/null +++ b/2025.03.14/Linux/a11.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include "array_io.h" +#include "io_status.h" +#include "solve.h" + +/* ./a.out n m p k [filename] */ +int main(int argc, char *argv[]) +{ + double t, res, *a; + int n, m, p, k, task = 11; + char *name = 0; + + if (!((argc == 5 || argc == 6) && + sscanf(argv[1], "%d", &n) == 1 && + sscanf(argv[2], "%d", &m) == 1 && + sscanf(argv[3], "%d", &p) == 1 && + sscanf(argv[4], "%d", &k) == 1 && + k >= 0 && k <= 4 && (!(k == 0 && argc != 6)))) + { + printf("Usage: %s n m p k [filename]\n", argv[0]); + return 1; + } + if (argc == 6) name = argv[5]; + + a = (double *)malloc(n * m * sizeof(double)); + if (!a) + { + printf("Not enough memory\n"); + return 2; + } + + if (name) + { /* из файла */ + io_status ret; + ret = read_matrix(a, n, m, name); + do { + switch (ret) + { + case SUCCESS: + continue; + case ERROR_OPEN: + printf("Cannot open %s\n", name); + break; + case ERROR_READ: + printf("Cannot read %s\n", name); + } + free(a); + return 3; + } while (0); + } else init_matrix(a, n, m, k); + + printf("Matrix:\n"); + print_matrix(a, n, m, p); + + t = clock(); + res = t11_solve(a, n, m); + t = (clock() - t) / CLOCKS_PER_SEC; + + printf("New matrix:\n"); + print_matrix(a, n, m, p); + printf ("%s : Task = %d Result = %e Elapsed = %.2f\n", argv[0], task, res, t); + + free(a); + return 0; +} diff --git a/2025.03.14/Linux/array_io.c b/2025.03.14/Linux/array_io.c new file mode 100644 index 0000000..6e56ecf --- /dev/null +++ b/2025.03.14/Linux/array_io.c @@ -0,0 +1,40 @@ +#include +#include "array_io.h" + +io_status read_matrix(double *a, int n, int m, const char *name) +{ + int i, j; + FILE *fp; + if (!(fp = fopen(name, "r"))) return ERROR_OPEN; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (fscanf(fp, "%lf", a + i * m + j) != 1) + {fclose(fp); return ERROR_READ;} + fclose(fp); + return SUCCESS; +} + +void print_matrix(const double *a, int n, int m, int p) +{ + int np = (n > p ? p : n); + int mp = (m > p ? p : m); + int i, j; + + for (i = 0; i < np; i++) + { + for (j = 0; j < mp; j++) + printf(" %10.3e", a[i * m + j]); + printf("\n"); + } +} + +void init_matrix(double *a, int n, int m, int k) +{ + double (*q)(int, int, int, int); + double (*f[])(int, int, int, int) = {f1, f2, f3, f4}; + int i, j; + q = f[k-1]; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + a[i * m + j] = q(n, m, i+1, j+1); +} diff --git a/2025.03.14/Linux/array_io.h b/2025.03.14/Linux/array_io.h new file mode 100644 index 0000000..e312a84 --- /dev/null +++ b/2025.03.14/Linux/array_io.h @@ -0,0 +1,11 @@ +#ifndef ARRAY_IO_H +#define ARRAY_IO_H + +#include "io_status.h" +#include "init_f.h" + +io_status read_matrix(double *a, int n, int m, const char *name); +void print_matrix(const double *a, int n, int m, int p); +void init_matrix(double *a, int n, int m, int k); + +#endif diff --git a/2025.03.14/Linux/init_f.c b/2025.03.14/Linux/init_f.c new file mode 100644 index 0000000..925afb5 --- /dev/null +++ b/2025.03.14/Linux/init_f.c @@ -0,0 +1,30 @@ +#include "init_f.h" +#include + +#define MAX(n, m) (n < m ? m : n) + +double f1(int n, int m, int i, int j) +{ + return MAX(n, m) - MAX(i, j) + 1; +} + +double f2(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return MAX(i, j); +} + +double f3(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return abs(i - j); +} + +double f4(int n, int m, int i, int j) +{ + (void)n; + (void)m; + return 1./(i+j-1); +} diff --git a/2025.03.14/Linux/init_f.h b/2025.03.14/Linux/init_f.h new file mode 100644 index 0000000..691aace --- /dev/null +++ b/2025.03.14/Linux/init_f.h @@ -0,0 +1,9 @@ +#ifndef INIT_F_H +#define INIT_F_H + +double f1(int n, int m, int i, int j); +double f2(int n, int m, int i, int j); +double f3(int n, int m, int i, int j); +double f4(int n, int m, int i, int j); + +#endif diff --git a/2025.03.14/Linux/io_status.h b/2025.03.14/Linux/io_status.h new file mode 100644 index 0000000..420a981 --- /dev/null +++ b/2025.03.14/Linux/io_status.h @@ -0,0 +1,13 @@ +#ifndef IO_STATUS_H +#define IO_STATUS_H + +#define LEN 1234 + +typedef enum _io_status +{ + SUCCESS, + ERROR_OPEN, + ERROR_READ +} io_status; + +#endif diff --git a/2025.03.14/Linux/solve.c b/2025.03.14/Linux/solve.c new file mode 100644 index 0000000..c6acad8 --- /dev/null +++ b/2025.03.14/Linux/solve.c @@ -0,0 +1,241 @@ +#include "solve.h" +#include + +#define eps 1e-9 + +int compare(const double a, const double b) +{ + if (a - b > eps) return 1; + else if (b - a > eps) return -1; + return 0; +} + +double t1_solve(double *a, int n, int m) +{ + int i, j; + double cur = 0, maximum = 0; + if (n > 0) + for (j = 0; j < m; j++) maximum += fabs(a[j]); + for (i = 1; i < n; i++) + { + cur = 0; + for (j = 0; j < m; j++) + cur = fabs(a[i * m + j]); + if (compare(cur, maximum) == 1) maximum = cur; + } + + return maximum; +} + +double t2_solve(double *a, int n, int m) +{ + int i, j; + double cur = 0, maximum = 0; + if (m > 0) + for (i = 0; i < n; i++) maximum += fabs(a[i * m]); + for (j = 1; j < m; j++) + { + cur = 0; + for (i = 0; i < n; i++) + cur += fabs(a[i * m + j]); + if (compare(cur, maximum) == 1) maximum = cur; + } + + return maximum; +} + +double t3_solve(const double *A, const double *X, double *B, int m, int n) +{ + double r = 0; + int i, j; + for (i = 0; i < n; i++) B[i] = -B[i]; + + for (i = 0; i < n; i++) + { + for (j = 0; j < m; j++) + B[i] += A[i * m + j] * X[j]; + r += fabs(B[i]); + } + return r; +} + +double t4_solve(const double *A, const double *X, double *B, int m, int n) +{ + double maximum = 0, cur; + int i, j; + + for (i = 0; i < n; i++) + { + cur = -B[i]; + for (j = 0; j < m; j++) + cur += A[i * m + j] * X[j]; + cur = fabs(cur); + if (compare(cur, maximum) == 1) maximum = cur; + } + + return maximum; +} + +double t5_solve(const double *A, const double *b, int n, int m) +{ + double temp, summa, maximum = 0; + int i, j, k; + + if (n <= 0 || m <= 0) return 0; + + for (i = 0; i < n; i++) + { + summa = 0; + for (k = 0; k < n; k++) { + temp = 0; + for (j = 0; j < m; j++) + temp += A[i * m + j] * b[j * n + k]; + + if (k == i) temp--; + summa += fabs(temp); + } + if (compare(summa, maximum) == 1) maximum = summa; + } + + return maximum; +} + +double t6_solve(const double *A, const double *b, int n, int m) +{ + double temp, summa, maximum = 0; + int i, j, k; + + if (n <= 0 || m <= 0) return 0; + + + for (k = 0; k < n; k++) + { + summa = 0; + for (i = 0; i < n; i++) + { + temp = 0; + for (j = 0; j < m; j++) + temp += A[i * m + j] * b[j * n + k]; + + if (k == i) temp--; + summa += fabs(temp); + } + if (compare(summa, maximum) == 1) maximum = summa; + } + + return maximum; +} + +double t7_solve(double *a, int n, int m) +{ + int i, j; + double cur = 0, maximum = 0; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (i == 0 || i == n-1 || j == 0 || j == m-1) + if (compare(fabs(a[i*m + j]), maximum) == 1) + maximum = fabs(a[i*m + j]); + + for (i = 1; i < n-1; i++) + for (j = 1; j < m-1; j++) + { + cur = (a[(i-1)*m + j] + a[(i+1)*m + j] + a[i*m + (j-1)] + a[i*m + (j+1)]) / 5; + if (compare(fabs(cur), maximum) == 1) maximum = fabs(cur); + a[i*m + j] = cur; + } + + return maximum; +} + +double t8_solve(double *a, int n, int m) +{ + int i, j; + double cur = 0, maximum = 0; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (i == 0 || i == n-1 || j == 0 || j == m-1) + if (compare(fabs(a[i*m + j]), maximum) == 1) + maximum = fabs(a[i*m + j]); + + for (i = n-2; i > 0; i--) + for (j = m-2; j > 0; j--) + { + cur = (a[(i+1)*m + j] + a[(i-1)*m + j] + a[i*m + (j-1)] + a[i*m + (j+1)]) / 5; + if (compare(fabs(cur), maximum) == 1) maximum = fabs(cur); + a[i*m + j] = cur; + } + + return maximum; +} + +double t9_solve(double *a, int n, int m) +{ + int i, j; + double cur = 0, maximum = 0; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (i == 0 || i == n-1 || j == 0 || j == m-1) + if (compare(fabs(a[i*m + j]), maximum) == 1) + maximum = fabs(a[i*m + j]); + + for (i = 1; i < n-1; i++) + for (j = m-2; j > 0; j--) + { + cur = (a[(i-1)*m + j] + a[(i+1)*m + j] + a[i*m + (j-1)] + a[i*m + (j+1)]) / 5; + if (compare(fabs(cur), maximum) == 1) maximum = fabs(cur); + a[i*m + j] = cur; + } + + return maximum; +} + +double t10_solve(double *a, int n, int m) +{ + int i, j; + double cur = 0, maximum = 0; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (i == 0 || i == n-1 || j == 0 || j == m-1) + if (compare(fabs(a[i*m + j]), maximum) == 1) + maximum = fabs(a[i*m + j]); + + for (i = n-2; i > 0; i--) + for (j = 1; j < m-1; j++) + { + cur = (a[(i+1)*m + j] + a[(i-1)*m + j] + a[i*m + (j-1)] + a[i*m + (j+1)]) / 5; + if (compare(fabs(cur), maximum) == 1) maximum = fabs(cur); + a[i*m + j] = cur; + } + + return maximum; +} + +double t11_solve(double *a, int n, int m) +{ + int i, j, max_i = 0, max_j = 0; + double temp = 0, maximum = 0; + for (i = 0; i < n; i++) + for (j = 0; j < m; j++) + if (compare(fabs(a[i*m + j]), maximum) == 1) + { + maximum = fabs(a[i*m + j]); + max_i = i; + max_j = j; + } + if (max_i != 0) + for (j = 0; j < m; j++) + { + temp = a[max_i*m+j]; + a[max_i*m+j] = a[j]; + a[j] = temp; + } + if (max_j != 0) + for (i = 0; i < n; i++) + { + temp = a[i*m + max_j]; + a[i*m + max_j] = a[i*m]; + a[i*m] = temp; + } + + return maximum; +} diff --git a/2025.03.14/Linux/solve.h b/2025.03.14/Linux/solve.h new file mode 100644 index 0000000..6ceb39d --- /dev/null +++ b/2025.03.14/Linux/solve.h @@ -0,0 +1,17 @@ +#ifndef SOLVE_H +#define SOLVE_H + +int compare(const double a, const double b); +double t1_solve(double *a, int n, int m); +double t2_solve(double *a, int n, int m); +double t3_solve(const double *A, const double *X, double *B, int m, int n); +double t4_solve(const double *A, const double *X, double *B, int m, int n); +double t5_solve(const double *A, const double *b, int n, int m); +double t6_solve(const double *A, const double *b, int n, int m); +double t7_solve(double *a, int n, int m); +double t8_solve(double *a, int n, int m); +double t9_solve(double *a, int n, int m); +double t10_solve(double *a, int n, int m); +double t11_solve(double *a, int n, int m); + +#endif