Skip to content

Instantly share code, notes, and snippets.

@daniilgri
Last active November 8, 2018 20:33
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/d5b6ea78d4224f1aefebfc3634225df8 to your computer and use it in GitHub Desktop.
Save daniilgri/d5b6ea78d4224f1aefebfc3634225df8 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 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("y ---- %.lf\n", e);
while (1) {
above = pow(-1, k) * pow(x, k + 1);
printf("above: %.30lf\n", above);
fac = myFact(k + 1);
printf("fac: %.30lf\n", fac);
newSum = above / fac;
printf("newSum: %.30lf\n", newSum);
printf("sum: %.30lf\n", sum);
if (abs(newSum - sum) < e) {
break;
}
sum += newSum;
k++;
}
printf("Сумма: %.30f", 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