Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Java

Idiom #305 Calculate exponentiation of real numbers

Compute and print a^b, and a^n, where a and b are floating point numbers and n is an integer.

import static java.lang.Math.pow;
import static java.lang.System.out;
double x = pow(a, b), y = pow(a, n);
out.printf("%s, %s", x, y);
#include <stdio.h>
#include <math.h>
printf("%f %f", pow(a, b), pow(a, n));

New implementation...