Skip to content

Instantly share code, notes, and snippets.

@daniilgri
Last active November 8, 2018 19:27
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/4870c69ddeb85c7b54d1ac964735dafd to your computer and use it in GitHub Desktop.
Save daniilgri/4870c69ddeb85c7b54d1ac964735dafd to your computer and use it in GitHub Desktop.
#include "pch.h"
#include <stdio.h>
#include <windows.h>
#include <math.h>
double myFact(int n);
int main()
{
double x, sum = 0, ctg, min, fac;
SetConsoleOutputCP(1251);
SetConsoleCP(1251);
printf("Введите x:\n");
scanf_s("%f", &x);
for (int k = 1; k <= 8; k++) {
min = pow(-1, k);
printf("(-1)^k = %f\n", min);
ctg = 1 / pow(tan(x), k + 1);
printf("ctg = %f\n", ctg);
fac = myFact(k * 3);
printf("Факториал: %.f \n", fac);
printf("Формула: %.30f\n", min*ctg / fac);
sum += min * ctg / fac;
printf("Промеж. сумма: %.20f \n", sum);
}
printf("Сумма: %.20f", sum);
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