Last active
November 8, 2018 20:33
-
-
Save daniilgri/d5b6ea78d4224f1aefebfc3634225df8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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