I could use some help on this code that I am writing. I am trying to code a for loop to raise a power of a number here is what I have so far any sugg.
long lngBase = 0;
long lngRaise = 0;
long lngResult = 1;
lngBase = Convert.ToInt64(txtBase.Text);
lngRaise = Convert.ToInt64(txtExponent.Text);
for (lngBase = 1; lngBase <= lngRaise; lngBase++)
{
lngResult = lngBase * lngRaise;
}
txtResult.Text = lngResult.ToString("n0");
Loading
Pravin MorePosted Nov 28, 2011, 1:26 AM
long lngBase = 0;
long lngRaise = 0;
long lngResult = 1;
lngBase = Convert.ToInt64(txtBase.Text);
lngRaise = Convert.ToInt64(txtExponent.Text);
for (int i = 0; i < lngRaise; i++)
{
if (i == 0)
{
lngResult = lngBase;
}
else
lngResult = lngResult * lngBase;
}
txtResult.Text = lngResult.ToString("n0");
Thanks,
Pravin.