Сделал 46е, но не оформил в правильном виде
This commit is contained in:
parent
8b2e889036
commit
5d875464a3
1 changed files with 30 additions and 1 deletions
31
46Ex/main.c
31
46Ex/main.c
|
|
@ -1,7 +1,34 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "tools.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", ¤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;
|
||||||
|
|
@ -10,4 +37,6 @@ int main(void) {
|
||||||
|
|
||||||
printf("Enter the x cordinate: ");
|
printf("Enter the x cordinate: ");
|
||||||
scanf("%lf", &x);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue