Сделал 46е, но не оформил в правильном виде

This commit is contained in:
AZEN-SGG 2024-09-24 08:10:34 +03:00
parent 8b2e889036
commit 5d875464a3

View file

@ -1,7 +1,34 @@
#include <stdio.h>
#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", &current) != 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", &current) == 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);
}