Solved

Exponents in C#

Posted on 2003-11-18
4
3,515 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
  • 2
4 Comments
 
LVL 7

Assisted Solution

by:jj819430
jj819430 earned 20 total points
Comment Utility
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
Comment Utility
using System.Math;

...

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

Author Comment

by:pmesick12345
Comment Utility
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
Comment Utility
include Math.h most likely
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WPF issue with Trigger 2 65
C# remove trailing commas from csv file 10 45
Exception in Log4Net 1 18
Problem to open Excel file 15 38
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now