using System;
namespace recrusiontest
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Input x: ");
double x = double.Parse(Console.ReadLine());
Console.WriteLine("Input n: ");
int n = int.Parse(Console.ReadLine());
Console.WriteLine("Power is: {0:F6}",Power(x,n));
Console.WriteLine("Power using Math library is: {0:F6}",Math.Pow(x,n));
}
static public double Power(double x, int n)
{
int n1 = n/2;
int n2 = n-n1;
if(n==0) // base case 1: n==0
return 1.0;
else if(n==1) //base cace 2: n==1
return x;
else // recursive cases: n>=2
return Power(x,n1) * Power(x,n2);
}
}
}