math.pow int c# code example
Example 1: math.pow in C# using loop
static float CalculatePower(float x, int y)
{
float temp;
if (y == 0)
return 1;
temp = CalculatePower(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
{
if (y > 0)
return x * temp * temp;
else
return (temp * temp) / x;
}
}
Example 2: how does Pow work C#
//It does to the power of
Pow(2,3)
//this would do 2 to the power of 3