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=3

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.

This program takes two numbers from the user (a base number and an exponent) and calculates the power.

3 x 3=3

^{2}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.

3^{1}3 to the first power 3

3^{2}3 to the second power or 3 squared 3 x 3

3^{3}3 to the third power or 3 cubed 3 x 3 x 3

3^{6}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[ads id='ads1']^{ exponent }

### 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.#### Output

Enter base and exponent respectively: 2

12

2^12 = 4096

## إرسال تعليق