• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
June 01, 2022 |42.3K Views
C++ Program to Calculate Power of a Number
  Share  2 Likes
Description
Discussion

In this video, we will see a C++ Program to Calculate the Power of a Number.

To calculate the power of a number we use two different methods:

1. User defined function
2. In-built function [pow()]

User-defined function: Here we make a Power() which is a user-defined function and calculate the power using a While loop.
In-built function [pow()]: Given two numbers base and exponent, pow() function finds x raised to the power of y i.e. xy. pow() is function to get the power of a number, but we have to use #include in C++ to use that pow() function, then two numbers are passed.

Syntax: pow(base,exponent);
Pow() parameters:
1) Base: the base value
2) Exponent: exponent of the base

Pow() return value:
1) Result of base exponent
2) 1.0 if exponent is 0.
3) 0.0 if base is 0.

Example:
pow(4 , 2); Then we will get the result as 4^2, which is 16.

Input : x = 2, n = 3
Output : 8

Input : x = 7, n = 2
Output : 49

Calculate Power of a Number : https://www.geeksforgeeks.org/write-a-c-program-to-calculate-powxn/

Read More