Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
21
Task/Nth-root/C-sharp/nth-root.cs
Normal file
21
Task/Nth-root/C-sharp/nth-root.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(NthRoot(81,2,.001));
|
||||
Console.WriteLine(NthRoot(1000,3,.001));
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
public static double NthRoot(double A,int n, double p)
|
||||
{
|
||||
double _n= (double) n;
|
||||
double[] x = new double[2];
|
||||
x[0] = A;
|
||||
x[1] = A/_n;
|
||||
while(Math.Abs(x[0] -x[1] ) > p)
|
||||
{
|
||||
x[1] = x[0];
|
||||
x[0] = (1/_n)*(((_n-1)*x[1]) + (A/Math.Pow(x[1],_n-1)));
|
||||
|
||||
}
|
||||
return x[0];
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue