From 5d875464a30d7fa60f3f128ba119ccbc3e7c189a Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Tue, 24 Sep 2024 08:10:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=2046=D0=B5?= =?UTF-8?q?,=20=D0=BD=D0=BE=20=D0=BD=D0=B5=20=D0=BE=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D0=B8=D0=BB=20=D0=B2=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=BC=20=D0=B2=D0=B8=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 46Ex/main.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/46Ex/main.c b/46Ex/main.c index 20feeef..a25b94e 100644 --- a/46Ex/main.c +++ b/46Ex/main.c @@ -1,7 +1,34 @@ #include #include "tools.h" -int solutionPolynomial(FILE * file, double x, double * &derivative, double * &polynomial) +/* +Example: 5 4 3 2 1 +x: 2 + +Answer: 80 + 32 + 12 + 4 + 1 = 129 + 160 + 48 + 12 + 2 = 222 +*/ + +int solutionPolynomial(FILE * file, double x, double * derivative, double * polynomial); + +int solutionPolynomial(FILE * file, double x, double * derivative, double * polynomial) { + double current; + + if (fscanf(file, "%lf", ¤t) != 1) { + printf("File is empty!"); + return 1; + } + + *derivative = *polynomial = 0; + + do { + *derivative = *derivative * x + *polynomial; + *polynomial = *polynomial * x + current; + // c4x^3 + c3x^2 + c2x + c = c = c2x + c = c3x^2 + c2x + c = ... + } while (fscanf(file, "%lf", ¤t) == 1); + + return 0; +} int main(void) { double x, derivative, polynomial; @@ -10,4 +37,6 @@ int main(void) { printf("Enter the x cordinate: "); scanf("%lf", &x); + if (solutionPolynomial(file, x, &derivative, &polynomial)) return 1; + printf("The solution of the polynomial is %.0lf\nThe solution of the derivative is %.0lf", polynomial, derivative); }