Description
To calculate the power of a number, the base and power is user input. Here pow() function used for calculating the power.
C/C++
/* C Program to calculate power of a number */ //Save it as PowerOfNumber.c #include<stdio.h> int main(){ double base, power; printf("Enter a base : "); scanf("%lf",&base); printf("Enter power : "); scanf("%lf",&power); double value = pow(base, power); printf("%lf^%lf = %lf",base,power,value); return 0; }
Input: Enter a base : 2 Enter power : 5 Output: 2.0^5.0 = 32.0
Java
/* Java Program to calculate power of a number */ //Save it as PowerOfNumber.java import java.io.*; import java.util.Scanner; public class PowerOfNumber { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter a base : "); double base = scanner.nextDouble(); System.out.println("Enter power : "); double power = scanner.nextDouble(); double value = Math.pow(base, power); System.out.println(base+"^"+power+" = "+value); } }
Input: Enter a base : 2 Enter power : 5 Output: 2.0^5.0 = 32.0
Related Programs
1) Add Two Numbers2) Program to subtract two numbers
3) Program to multiply two numbers
4) Program to divide two numbers
5) Program to find modulus of two numbers
6) Program to find Quotient and Remainder
7) Program to calculate Permutation And Combination
8) Program to find simple interest
9) Program to calculate Gross Salary
10) Program to calculate percentage mark of student