#include <stdio.h>
#include <math.h>
#include "functions.h"
#include "functions.cpp"
int main() {
double x, y, s, diff;
printf("| x | Y(x) | S(x) | |Y(x) - S(x)| |\n");
printf("--------------------------------------------------------------------------\n");
for (x = A; x <= B + 1e-9; x += H) {
y = Y (x);
s = S (x, N);
diff = fabs(y - s);
printf("| %.3f | %9.16f | %9.16f | %13.16f |\n", x, y, s, diff);
}
return 0;
}
#include <math.h>
double Y(double x) {
return 2 * (pow(cos(x), 2) - 1);
}
double S(double x, int n) {
double sum = 0;
double numerator, denominator, term;
for (int k = 1; k <= n; ++k) {
numerator = pow(-1, k) * pow(2 * x, 2 * k);
denominator = 1;
for (int j = 1; j <= 2 * k; ++j) {
denominator *= j;
}
term = numerator / denominator;
sum += term;
}
return sum;
}
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
// Константи згідно з умовою завдання
#define A 0.1
#define B 1.0
#define H 0.1
#define N 80
double Y(double x);
double S(double x, int n);
#endif