Question
Write a program to calculate theĀ power of a number.
Enter the number
2
Enter the Exponent
3
2^3=8
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
Java
Python
Java
import java.util.*;
public class powerOfNumber
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number ");
int num=sc.nextInt();
System.out.println("Enter the Exponent");
int exp=sc.nextInt();
int power=(int)Math.pow(num,exp);
System.out.println(num+"^"+exp+"="+power);
}
}
Python
number=int(input("Enter a number: "))
exponent=int(input("Enter the exponent: "))
power=number**exponent
print(number,"^",exponent,"=",power)