Exponents in C#

How do you use Exponents in C#?  It doesnt seem to have a Math library.
pmesick12345Asked:
Who is Participating?
 
wile_e_coyoteCommented:
using System.Math;

...

int x = 4
int y = pow (x, 3);    // returns x raised to the 3rd power
0
 
jj819430Commented:
I would just create a routine to do it.
You can do it any way you want, with recursion or what not.

// this is UNTESTED code. May have errors
public int power(int base, int power)
{
if(power == 1)
{
return base;
}

return base * power(base, power-1);
}
0
 
pmesick12345Author Commented:
it is simply Math.pow(base, exponent)
I didnt have to include anything extra in the "using" section
0
 
jj819430Commented:
include Math.h most likely
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.