aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--LICENSE24
-rw-r--r--Makefile20
-rw-r--r--README.md15
-rw-r--r--libs/libpoly.c7
-rw-r--r--libs/libsin.c7
-rw-r--r--libs/libsq.c4
-rw-r--r--main.c72
7 files changed, 20 insertions, 129 deletions
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index fdddb29..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,24 +0,0 @@
-This is free and unencumbered software released into the public domain.
-
-Anyone is free to copy, modify, publish, use, compile, sell, or
-distribute this software, either in source code form or as a compiled
-binary, for any purpose, commercial or non-commercial, and by any
-means.
-
-In jurisdictions that recognize copyright laws, the author or authors
-of this software dedicate any and all copyright interest in the
-software to the public domain. We make this dedication for the benefit
-of the public at large and to the detriment of our heirs and
-successors. We intend this dedication to be an overt act of
-relinquishment in perpetuity of all present and future rights to this
-software under copyright law.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-For more information, please refer to <https://unlicense.org>
diff --git a/Makefile b/Makefile
index fdb2c0c..79b383d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,18 +1,2 @@
-
-all: main libs
-
-# the main program
-main: main.c
- cc -o main main.c
-
-# available libraries
-.PHONY: libs
-libs: libs/*
- cc -shared libs/libsq.c -lm -lc -o libsq
- cc -shared libs/libsin.c -lm -lc -o libsin
- cc -shared libs/libpoly.c -lm -lc -o libpoly
-
-# clear build
-.PHONY: clean
-clean:
- rm -f main libsq libsin libpoly
+sin: main.c
+ cc -o sin main.c
diff --git a/README.md b/README.md
deleted file mode 100644
index 8dc07f1..0000000
--- a/README.md
+++ /dev/null
@@ -1,15 +0,0 @@
-# Файлы
-* main.c: главный файл
-* Makefile: система сброки GNU Make
-* libs/ : папка с библиотеками для теста. а каждом файле там по 1 функции.
-
-# Как протестировать
-## Требования
-* ОС: Unix
-* gnu make
-* командная строка
-## Сборка
-* cd <путь к этому файлу>
-* make all
-## Запуск
-`./main ./libsq `. вместо libsq может быть libsin, libpoly
diff --git a/libs/libpoly.c b/libs/libpoly.c
deleted file mode 100644
index 2daa972..0000000
--- a/libs/libpoly.c
+++ /dev/null
@@ -1,7 +0,0 @@
-
-#include <math.h>
-
-// calculate polynomial
-double f(double x) {
- return pow(x, 3) - 2*x*x - 10*x + 69;
-}
diff --git a/libs/libsin.c b/libs/libsin.c
deleted file mode 100644
index 34200af..0000000
--- a/libs/libsin.c
+++ /dev/null
@@ -1,7 +0,0 @@
-
-#include <math.h>
-
-// calculate sine
-double f(double x) {
- return sin(x);
-}
diff --git a/libs/libsq.c b/libs/libsq.c
deleted file mode 100644
index 2b93fb4..0000000
--- a/libs/libsq.c
+++ /dev/null
@@ -1,4 +0,0 @@
-// calculate square
-double f(double x) {
- return x*x;
-}
diff --git a/main.c b/main.c
index 76afcef..74277f0 100644
--- a/main.c
+++ b/main.c
@@ -1,59 +1,23 @@
+#include <stdio.h>
-/*
- * Сотов Константин Алексеевич, 117 группа
- * sotov@twistea.su +7 914 329 50 01
- *
- * Данный код загружает динамическую библиотеку,
- * имя которой передано в аргументах командной строки,
- * и считает интеграл функции "f", если она есть
- * в этой динамической библиотеке.
- */
+#define EPSILON 0.001*0.001
+#define MAX_ITERATIONS 100
-#include <stdio.h> // printf, scanf
-#include <stdlib.h> // exit
-#include <dlfcn.h> // dlopen, dlsym, dlclose
+int main(void) {
+ double x;
+ double result;
+ double last_elem;
+ int i;
+
+ printf("Input a number\n");
+ scanf("%lf", &x);
+ last_elem = result = x;
-
-// Integrates function f from a to b with <sums> steps.
-// Uses "naive" and straightforward integration technique
-// Assumes a < b
-double integral(double (*f)(double), double a, double b, int sums) {
- double result = 0;
- const double dx = (b-a)/sums;
- for (double i = a; i < b; i += dx)
- result += dx * f(i);
- return result;
-}
-
-int main(int argc, char* argv[]) {
- if (argc != 2) {
- printf("Недостаточно аргументов. использование:\n"
- "%s <путь к динамической библиотеке>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
- // Open the dynamic library
- void* handle = dlopen(argv[1], RTLD_NOW);
- if (handle == NULL) {
- printf("ERROR: %s\n", dlerror());
- exit(EXIT_FAILURE);
+ for (i = 1; i < MAX_ITERATIONS; ++i) {
+ last_elem = last_elem * x * x / (2*i * (2*i+1));
+ if (last_elem*last_elem <= EPSILON) break;
+ result += last_elem * ( (i%2 * -2) + 1 );
}
- // Locate the function
- void* f = dlsym(handle, "f");
- if (f == NULL) {
- printf("ERROR: %s", dlerror());
- dlclose(handle);
- exit(EXIT_FAILURE);
- }
-
- // Input-output block
- const char* fullname
- = "Сотов Константин Алексеевич";
- printf("Автор: %s\n", fullname);
- double a, b;
- puts("Введите нижнюю и верхнюю границы интегрирования через пробел");
- scanf("%lf %lf", &a, &b);
- printf("Интеграл f от %lf до %lf = %lf\n",
- a, b, integral(f, a, b, 10000));
-
- exit(EXIT_SUCCESS);
+ printf("result = %lf; iterations = %i; last_elem = %lf\n", result, i, last_elem);
+ return 0;
}