Thanks a lot Mike for the solution
I am trying to do the the calculation without the use of built in pwr
function.I have to use the for or while loop with probably the counter
Thanks once again
David
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:8q*****************@newsread2.news.pas.earthl ink.net...
"David" <d_***@shaw.ca> wrote in message
news:7Ujec.78302$Pk3.72421@pd7tw1no... How can you write a program in C++ by using loop to control the
calculation without the use of library function pwr .For example 3 to the power of 4
(ie 3x3x3x3). Any help will be appreciated
#include <iostream>
unsigned int pwr(unsigned int base, unsigned int exp)
{
unsigned int result = 1;
while(exp--)
result *= base;
return result;
}
int main()
{
std::cout << pwr(3, 4) << '\n';
return 0;
}
-Mike