crap...I should have asked...what is your profession? you're not a student are you?
Main Topics
Browse All Topicshi,
how can write a function in C# to calcuate power and display in textbox?
ayha
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Incidentally, there's a couple things wrong with your code silemone:
1) You need to store the original number and mutliply by that. In your code running 2 ^ 3 for example, you'd end up with 2 * 2 first resulting in four, 2nd loop would then run 4 *4, NOT 4 * 2 which it should be.
2) You need to drop the <= in your loop to a <, otherwise you're going to have an extra multiplication.
Okay, so a final note on this:
IF you are only going to use integer values, then it's probably worthwhile to do inline coding as shown. There's a host of discussion online about this. Basically Math.Pow has to take into account fracional expononents to be reliable, to the math behind it is far more complicated than integer multiplication.
I haven't run tests myself, but general concensus seems to be custom function will outperform Math.Pow in integer exponents.
If your using doubles or just don't want to bother, then Math.Pow is the way to go.
Modified code is below to allow for proper negative exponents:
Business Accounts
Answer for Membership
by: silemonePosted on 2009-10-19 at 08:15:03ID: 25605903
textbox.text = calculatePower(num, pow);
public string calculatePower(int num, int pow)
{
int x = 1;
if (pow < 1)
return "0";
if (pow == 1)
return num.ToString();
for (int i = 1; i <= pow; i++)
{
x*=x;
}
return x.ToString();
}