Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include "pch.h"
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <math.h>
double myFact(int n);
int main()
{
SetConsoleOutputCP(1251);
SetConsoleCP(1251);
int k = 1;
double sum = 0, newSum = 0, above, fac, e, x;
printf("Введите x и e: \n");
scanf_s("%lf%lf", &x, &e);
printf("x ---- %.lf\n", x);
printf("e ---- %.lf\n", e);
while (1) {
above = pow(-1, k + 1) * pow(x, k);
printf("above: %.30f\n", above);
fac = myFact(2 * k);
printf("fac: %.30f\n", fac);
newSum = above * pow(x / 4, 3 * k) / fac;
printf("newSum: %.30f\n", newSum);
std::cout << "----------------" << abs(newSum - sum) << "\n";
if (abs(newSum - sum) < e) {
printf("Всё");
break;
}
sum += newSum;
k++;
}
printf("Сумма: %.30lf", newSum);
return 0;
}
double myFact(int n) {
double result = 1;
if (n == 0) { return result; }
for (int i = 1; i <= n; i++)
{
result *= i;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment