Solved

Exponents in C#

Posted on 2003-11-18
4
3,529 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

735 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