Answers for "how to use math.pow"

16

how to use pow function in java

import java.lang.Math; 
  
class Gfg { 
  
    // driver code 
    public static void main(String args[]) 
    { 
        double a = 30; 
        double b = 2; 
        System.out.println(Math.pow(a, b)); 
  
        a = 3; 
        b = 4; 
        System.out.println(Math.pow(a, b)); 
  
        a = 2; 
        b = 6; 
        System.out.println(Math.pow(a, b)); 
    }
Posted by: Guest on May-01-2020
0

pow without math.h

int pow(int base, int exp)
    {
      if(exp < 0)
        return -1;

        int result = 1;
        while (exp)
        {
            if (exp & 1)
                result *= base;
            exp >>= 1;
            base *= base;
        }

        return result;
    }
Posted by: Guest on March-27-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language