C++ program to calculate power of a number

C++ program to calculate power of a number
We know how to calculate the expression 3 x 3. This expression can be written in a shorter way using something called exponents.

3 x 3=32

An expression that represents repeated multiplication of the same factor is called a power.
The number 3 is called the base, and the number 2 is called the exponent. The exponent corresponds to the number of times the base is used as a factor.

31       3 to the first power 3
32       3 to the second power or 3 squared 3 x 3
33       3 to the third power or 3 cubed 3 x 3 x 3
36       3 to the power of six 3 x 3 x 3 x 3 x 3 x 3

This program takes two numbers from the user (a base number and an exponent) and calculates the power.
Power of a number = base  exponent
[ads id='ads1']

Example: Power of a number 

function power() is used to calculate the power of a number, for loop is used to runs from 1 to exponent. For each iteration of the loop, base is multiplied with power. i.e base is multiplied with itself exponent times and the result is stored in power. This will leads to base exponent  is stored in power.


Enter base and exponent respectively: 2
2^12 = 4096

Post a Comment

أحدث أقدم