• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
July 03, 2022 |1.2K Views

C Program to Calculate the Power of a Number

  Share   Like
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 four different methods:

1. Using while loop
2. Using In-built pow() function

Using While loop: In the first approach, we will calculate the power using the While loop.

Using In-built function [pow()] of C: Given two numbers base and exponent, pow() function finds x raised to the power of y is a function to get the power of a number, but we have to use math.h header file, then two numbers are passed.

Syntax: pow(base,exponent);

Pow() parameters:
- Base: the base value
- Exponent: exponent of the base

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

Input : x = 2, n = 5
Output : 32
Input : x = 6, n = 2
Output : 36

Apart from that, we will see the Time and Space complexity of these approaches.

C program to calculate power of a number: https://www.geeksforgeeks.org/write-a-c-program-to-calculate-powxn/