2_1

Run Settings
LanguageC
Language Version
Run Command
/* * @file lab2_1.c * @author Герасимюк Д.В., гр. 515і1 * @date 12 березня 2024 * @brief Лабораторна робота №2, варіант 3 * Модульне тестування. Завдання 1 */ #include "const.h" #include <math.h> //константи const double a = 0.1; const double b = 1.0; const double h = 0.1; const int n = 160; //Y(x) double Y(double x) { return ((x * x / 4) + (x / 2) + 1) * expl(x / 2); } //S(x) double S(double x) { double result = 0.0; double term; for (int i = 1; i <= n; ++i) { term = ((pow(n, 2) + 1.0 / tgamma(i)) * pow(x / 2, i)); result += term; } return result; }
#include <stdio.h> #include "const.h" #include <math.h> int main() { printf("| x | Y(x) | S(x) | |Y(x) - S(x)| |\n"); printf("|-------|-------------------|-------------------|---------------|\n"); double x; for (x = a; x <= b; x += h) { double Y_val = Y(x); double S_val = S(x); double diff = fabsl(Y_val - S_val); printf("| %5.2f | %17.5f | %17.5f | %12.5f |\n", x, Y_val, S_val, diff); } return 0; }
#ifndef CONST_H #define CONST_H extern const double a; extern const double b; extern const double h; extern const int n; double Y( double x); double S( double x); #endif
Editor Settings
Theme
Key bindings
Full width
Lines