Ask a Question related to PHP Notes, Design and Development.
-
didou@php.net #1
note 33908 deleted from control-structures.while by didou
Note Submitter: Merve
----
If you want to calculate powers, but you're having trouble with negative numbers and zero, use this code. It's still not compatible with a decimal number as the power (I'm working on that, but I doubt I'll ever be able to). All you have to do is include a bunch of if-then statements, along with the while loop. For those of you unfamiliar with special characters = is = and <sup> puts your stuff in superscript.
<?php
if ($b==0) {
print (" $a<sup>$b</sup> = 1");
}
elseif ($b<0) {
$c = $a;
$d = $b;
$f = ($b*-1);
while ($f>1)
{
$a = ($a*$c);
$f--;
}
$e = (1/$a);
print (" $c<sup>$d</sup> = $e");
} else {
$c = $a;
$d = $b;
while ($b>1)
{
$a = ($a*$c);
$b--;
}
print (" $c<sup>$d</sup> = $a");
}
}
?>
So, making your calculator will be a cinch.
didou@php.net Guest
-
note 33911 deleted from control-structures by didou
Note Submitter: Merve ---- If you're making if statements within if statements (it's possible for those of you who didn't know), you might be... -
note 33828 deleted from security by didou
Note Submitter: Anonymous ---- chroots are _not_ something you can throw at an insecure application, and expect it to magicaly save your arse... -
note 21357 deleted from function.is-a by didou
Note Submitter: krisher@oswego.edu ---- Any implementation of is_a that relies on empty() to test whether the object parameter is empty will... -
note 18675 deleted from ref.mssql by didou
Note Submitter: php@fireball88.de ---- Easy Oracle-Connection with my Class for Oracle/mySQL/MSSQL! my cDBC-Klass is free and with... -
note 29986 deleted from ref.objaggregation by didou
Note Submitter: galland@appli-box.com ---- bugfree object association example : <?php /** * corrected example of object association ...



Reply With Quote

