Problem Statement:Given base and exponent , find the power without using inbuilt functionInput FormatGiven two integers base and exponentOutput FormatPrint the powerConstraints1<= n <= 1000000NOTE : The calculated power value might exceed integer range.Sample Input 1:10 3Sample Output 1:1000Sample Input 2:3 4Sample Output 2:81
Question
Problem Statement:Given base and exponent , find the power without using inbuilt functionInput FormatGiven two integers base and exponentOutput FormatPrint the powerConstraints1<= n <= 1000000NOTE : The calculated power value might exceed integer range.Sample Input 1:10 3Sample Output 1:1000Sample Input 2:3 4Sample Output 2:81
Solution
Sure, here is a step-by-step solution to the problem in Python:
Step 1: Define a function that takes two parameters, base and exponent.
def power(base, exponent):
Step 2: Initialize a variable result to 1. This will hold our final answer.
result = 1
Step 3: Use a for loop to multiply the base to the result, exponent number of times.
Similar Questions
Write a function to calculate power of a number raised to other.
Find whether the given number is power of 2 or not.Input Format:Accept an Integer as inputOutput Format:Print the output as "YES" or "NO"Constraints:1<=INPUT<=10^15Sample Input 1:128Sample Output 1:YESSample Input 2:36Sample Output 2:NO
Given a non-negative integer N, the task is to check if N is a power of 2. Print 'YES' if N is the power of 2; else, print 'NO'.Example 1Input: N = 8Output: YESExplanation: 8 is equal to 2 raised to 3 (23 = 8).Example 2Input: N = 98Output: NOExplanation: 98 cannot be obtained by any power of 2.Note: This question was asked in Adobe coding test.Input format :The input consists of an integer N, representing the non-negative integer.
Implement pow(x, n), which calculates x raised to the power n (i.e., xn). Example 1:Input: x = 2.00000, n = 10Output: 1024.00000Example 2:Input: x = 2.10000, n = 3Output: 9.26100
Implement pow(x, n), which calculates x raised to the power n (i.e., xn). Example 1:Input: x = 2.00000, n = 10Output: 1024.00000Example 2:Input: x = 2.10000, n = 3Output: 9.26100Example 3:Input: x = 2.00000, n = -2Output: 0.25000Explanation: 2-2 = 1/22 = 1/4 = 0.25 Constraints:-100.0 < x < 100.0-231 <= n <= 231-1n is an integer.Either x is not zero or n > 0.-104 <= xn <= 104
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.