Find power of a number

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
CodingNinjas
author
2y
Using while() loop

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.

Space Compl...read more
Help your peers!
Add answer anonymously...
HSBC Group Software Engineer Trainee Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter