Solved

Exponents in C#

Posted on 2003-11-18
4
3,531 Views
Last Modified: 2008-10-12
How do you use Exponents in C#?  It doesnt seem to have a Math library.
0
Comment
Question by:pmesick12345
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Assisted Solution

by:jj819430
jj819430 earned 20 total points
ID: 9773045
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
 
LVL 4

Accepted Solution

by:
wile_e_coyote earned 30 total points
ID: 9773634
using System.Math;

...

int x = 4
int y = pow (x, 3);    // returns x raised to the 3rd power
0
 

Author Comment

by:pmesick12345
ID: 9774184
it is simply Math.pow(base, exponent)
I didnt have to include anything extra in the "using" section
0
 
LVL 7

Expert Comment

by:jj819430
ID: 9774195
include Math.h most likely
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question