Advertisement
dxeqtr

RecursiveSqrt

Jun 14th, 2020
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. namespace _03.SquareRoot
  5. {
  6.     class Program
  7.     {
  8.         public static decimal Sqrt(int number, decimal root)
  9.  
  10.         {
  11.             if (Math.Abs(root * root - number) <= 0.00000000001M)
  12.                 return root;
  13.  
  14.             return Sqrt(number, root - ((root * root) - number) / (2 * root));
  15.         }
  16.  
  17.         static void Main(string[] args)
  18.         {
  19.  
  20.             decimal root = Sqrt(12345, 10);
  21.  
  22.             Console.WriteLine(root);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement