mirror of
https://github.com/ada-dmitry/tmp_project.git
synced 2026-09-24 01:10:31 +00:00
s
This commit is contained in:
+1
-10
@@ -3,11 +3,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
static wait = 1;
|
||||
|
||||
double f(double x)
|
||||
{
|
||||
return x + x - 16;
|
||||
return x * x - 16;
|
||||
}
|
||||
|
||||
void find_zero(double *pa, double *pb, double eps, double *px)
|
||||
@@ -22,15 +20,8 @@ void find_zero(double *pa, double *pb, double eps, double *px)
|
||||
|
||||
void ctrlc_handler(int signum)
|
||||
{
|
||||
|
||||
printf("\nПолучен сигнал Ctrl+C\n");
|
||||
printf("Продолжить поиск корня? (C - продолжить, A - закончить работу программы, R - начать поиск на другом отрезке): ");
|
||||
while (getchar() != '\n')
|
||||
{
|
||||
printf("listener: stop");
|
||||
wait = 0;
|
||||
_getch();
|
||||
}
|
||||
}
|
||||
// void choose_path(char *choice);
|
||||
// void new_row(double *pa, double *pb);
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
double f(double x); // function x
|
||||
void find_zero(double *pa, double *pb, double eps, double *px); //
|
||||
@@ -11,13 +12,27 @@ int main()
|
||||
{
|
||||
double a, b, eps, x, *pa = &a, *pb = &b, *px = &x;
|
||||
char choice = ' ', *ch = &choice;
|
||||
sigset_t set;
|
||||
int sig;
|
||||
|
||||
printf("Введите интервал [a, b] и точность eps: ");
|
||||
scanf("%lf %lf %lf", pa, pb, &eps);
|
||||
|
||||
// if (a > b || )
|
||||
|
||||
find_zero(pa, pb, eps, px);
|
||||
|
||||
// Создание набора сигналов и добавление в него SIGINT
|
||||
sigemptyset(&set);
|
||||
sigaddset(&set, SIGINT);
|
||||
|
||||
// Блокировка SIGINT
|
||||
sigprocmask(SIG_BLOCK, &set, NULL);
|
||||
|
||||
// Ожидание получения сигнала Ctrl+C с помощью sigwait
|
||||
sigwait(&set, &sig);
|
||||
signal(SIGINT, ctrlc_handler);
|
||||
|
||||
printf("Корень уравнения: %lf\n", *px);
|
||||
printf("Работа программы завершена.\n");
|
||||
|
||||
|
||||
Executable
BIN
Binary file not shown.
Reference in New Issue
Block a user