Skip to content

Instantly share code, notes, and snippets.

@daniilgri
Created November 8, 2018 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniilgri/8ace2e49cf1db62231b6b0c37090fe45 to your computer and use it in GitHub Desktop.
Save daniilgri/8ace2e49cf1db62231b6b0c37090fe45 to your computer and use it in GitHub Desktop.
#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 n = 1;
double sum = 0, newSum = 0, first, fac, sn, e, x;
printf("Введите x и e: \n");
scanf_s("%lf%lf", &x, &e);
printf("x ---- %.lf\n", x);
printf("e ---- %.lf\n", e);
while (1) {
first = pow(-1, 2 * n + 1);
printf("first: %.30f\n", first);
sn = sin(n * x);
printf("sn: %.30f\n", sn);
fac = myFact(n + 3);
printf("fac: %.30f\n", fac);
newSum = first * sn / fac;
printf("newSUM = %.30f\n", newSum);
std::cout << "----------------" << abs(newSum - sum) << "\n";
if (abs(newSum - sum) < e) {
printf("Всё");
break;
}
sum += newSum;
n++;
}
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