Implement Pow(x, n)

Get a Strong Hold DSA practice problem on Onlearn.

Difficulty: medium.

Topics: Implementing power function: calculating x raised to the power n (pow(x, n)), Time Complexity, Space Complexity, Loops, Conditional Statements, Brute Force, Mathematical Algorithms, Optimization, Data Types, Basic Arithmetic, mathematical operations, complexity analysis, exponentiation, brute force, Binary Exponentiation, Number Manipulation.

Calculate Power (x^n) Given a double x and an integer n, calculate x raised to the power n. Problem Statement Implement pow(x, n), which calculates x raised to the power n (i.e., x^n). Input Specification The first line contains a double x. The second line contains an integer n. Output Specification Return x raised to the power n as a double. Examples Example 1: Input: x = 2.00000 n = 10 Output: 1024.00000 Explanation: You need to calculate 2.00000 raised to 10 which gives ans 1024.00000 Example 2: Input: x = 2.10000 n = 3 Output: 9.26100 Explanation: You need to calculate 2.10000 raised to 3 which gives ans 9.26100