Доделал 46е задание
This commit is contained in:
parent
5d875464a3
commit
973e407a45
6 changed files with 41 additions and 21 deletions
BIN
45Ex/a.exe
BIN
45Ex/a.exe
Binary file not shown.
1
46Ex/input.txt
Normal file
1
46Ex/input.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
5 4 3 2 1
|
22
46Ex/main.c
22
46Ex/main.c
|
@ -1,5 +1,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
#include "solution_polynomial.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Example: 5 4 3 2 1
|
Example: 5 4 3 2 1
|
||||||
|
@ -9,27 +10,6 @@ Answer: 80 + 32 + 12 + 4 + 1 = 129
|
||||||
160 + 48 + 12 + 2 = 222
|
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) {
|
int main(void) {
|
||||||
double x, derivative, polynomial;
|
double x, derivative, polynomial;
|
||||||
FILE * file = getFile();
|
FILE * file = getFile();
|
||||||
|
|
11
46Ex/makefile
Normal file
11
46Ex/makefile
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
all: main.o solution_polynomial.o tools.o
|
||||||
|
gcc main.o solution_polynomial.o tools.o && del *.o
|
||||||
|
|
||||||
|
main.o: main.c
|
||||||
|
gcc -c main.c
|
||||||
|
|
||||||
|
solution_polynomial.o: solution_polynomial.c
|
||||||
|
gcc -c solution_polynomial.c
|
||||||
|
|
||||||
|
tools.o: tools.c
|
||||||
|
gcc -c tools.c
|
20
46Ex/solution_polynomial.c
Normal file
20
46Ex/solution_polynomial.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "solution_polynomial.h"
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
8
46Ex/solution_polynomial.h
Normal file
8
46Ex/solution_polynomial.h
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef SOLUTION_POLYNOMIAL
|
||||||
|
#define SOLUTION_POLYNOMIAL
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int solutionPolynomial(FILE * file, double x, double * derivative, double * polynomial);
|
||||||
|
|
||||||
|
#endif // SOLUTION_POLYNOMIAL
|
Loading…
Add table
Add a link
Reference in a new issue