Last Updated: 4 Feb, 2021

Find power of a number

Easy
Asked in companies
AdobeFreshworksHSBC

Problem statement

Write a program to find x to the power n (i.e., x^n). Take x and n from the user. You need to print the answer.

Note: For this question, you can assume that 0 raised to the power of 0 is 1


Input format :
The only line of input contains two integers x and n separated by a single space.
Output Format :
The only line of output prints the power of the number.
Constraints:
0 <= x <= 8 
0 <= n <= 9

Approaches

01 Approach

Take input in two variable x and n. Create a variable ans and initialize it to 1

Run a while loop till n > 0. In each iteration mutilply your ans with x. Finally print ans.