settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Math Power - PHP Function Task

+1 vote

Create a function that calculates and returns the value of a number raised to a given power:

  • 28 = 256
  • 34 = 81

 

asked in PHP category by user ak47seo

1 Answer

0 votes

My function solution:

<?php

$number = readline();
$power = readline();

echo calculatePower($number, $power);

function calculatePower($n, $p) {

    $newNumber = 1;
    for ($i = 0; $i < $p; $i++) {
        $newNumber *= $n;
    }

    return $newNumber;
}
answered by user Jolie Ann
...