Answer the question
In order to leave comments, you need to log in
How to replace the recalculation with a coefficient?
The teacher made a remark:
You do not need to count the degrees for each term. It is required to find the relationship between them, the coefficient.
How to change the code to multiply by the coefficient?
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Введите X: ");
double x = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Введите K: ");
double k = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Введите EPS: ");
double EPS = Convert.ToDouble(Console.ReadLine());
if (Math.Abs(x) > 1)
{
Console.WriteLine("Неверное значение аргумента");
return;
}
double s = 0;
double last = 0;
for (int i = 0; ; i++)
{
double cur = (f(2 * i) * Math.Pow(x, 2 * i + 1)) / ((Math.Pow(4, i) * Math.Pow(f(i), 2) * (2 * i + 1)));
if (Math.Abs(cur - last) < EPS) break;
s += cur;
last = cur;
}
Console.WriteLine("f1()");
Console.WriteLine(Math.PI / 2 - s);
s = 0;
last = 0;
for (int i = 0;i<=k ; i++)
{
double cur = (f(2 * i) * Math.Pow(x, 2 * i + 1)) / ((Math.Pow(4, i) * Math.Pow(f(i), 2) * (2 * i + 1)));
s += cur;
last = cur;
}
Console.WriteLine("f2()");
Console.WriteLine(Math.PI/2 - s);
Console.WriteLine("f()");
Console.WriteLine(Math.Acos(x));
Console.ReadKey();
}
//факториал
static double f(int x)
{
return (x == 0) ? 1 : x * f(x - 1);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question