im just a 1st yr college student.can u help me this problems?

Compute the power of a number given the base and exponent. Do three versions of this program using a while loop, a do-while loop and a for-loop

Recommended Answers

All 3 Replies

I assume you don't know how to write a code for this. So before any code
is written. Think about how one would compute x^y, where x is the base
and y is the exponent.

Why is 2^10 = 1024 ? Why is 2^3 = 8 ?

yes. i dont know how and now im going crazy.can u show a sample program related to that?

Take out a piece of paper and write out 2^2 in terms of 2, then 2^3 in terms of two, and to the fourth in terms of two until you see the pattern. Break the product 2 ^ n down into n steps, take what happens at each step and do that in a loop. It's a repeated calculation that's why it's an ideal problem for a computer. Then generalize this to all numbers to all powers (within reason).

Try some code and post back with what you've got.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.