using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Program.FindAccuracy(10,-4,-4,1));
Console.ReadKey();
}
static double FindAccuracy(double num, double degree, double num1, double num2)
{
double Accuracy = Math.Pow( num,degree);
double[] root = Program.Interval(num1,num2);
double x1 = root[0], x2 = root[1];
double result ;
int i = 0;
do {
result = (x1 + x2) / 2;
if (i > 10) break;//остановка вручную что бы остановить бесконечный цикл
Console.WriteLine(result);
x1 = result;
i++;
} while (Math.Abs(result) > Accuracy) ;
return result;
}
static double[] Interval(double num1, double num2)
{
double value = (num1 + num2) / 2;
double[] interval = new double[2];
interval[0] = value;
if (num1 > 0 && value < 0 || num1 < 0 && value > 0)
interval[1] = num1;
else interval[1] = num2;
return interval;
}
}
}