function power($x, $y) { if ($y) { return $x; } else { return $x * power($x, $y - 1); } }
function power($val, $pow) { if ($pow == 0) { return 1; } elseif ($pow == 1) { return $val; } else { return $val * power($val, $pow - 1); } }
function power($x, $y) { if (!$y) { return 1; } if ($y) { return $x; } else { return $x * multiply($x, power($x, $y - 1)); } }
/** *1) Recursive relation * * n ^ m = n * n ^ m -1 * n * m = n + n * (m - 1); * 2) Bottom * m == 1 -> n * m == 1 -> n * 3) Step * -1 */ function power($n, $m) { if ($m < 0) { return 0; } if ($m == 0) { return 1; } if ($m == 1) { return $n; } return multiply(power($n, $m - 1), $n); }
function power($n) { if ($n == 1) { echo 'yes'; return; } if ($n % 2 != 0) { echo 'no'; return; } power($n / 2); return $n; }
function power($a, $n) { if ($n == 0) { return 1; } if ($n % 2 == 0) { $m = power($a, $n / 2); return $m * $m; } else { $x = power($a, $n - 1); return $a * $x; } $x = 10; return; }
function power($n, $p) { if ($p == '0') { return '1'; } else { if ($p == '1') { return bcmod($n, '10'); } else { if (bcmod($p, '2') != '0') { return bcmod(bcmul(bcmod($n, '10'), power(bcmod(bcmul($n, $n), '10'), bcdiv(bcsub($n, '1'), '2'))), '10'); } else { return bcmod(power(bcmod(bcmul($n, $n), '10'), bcdiv($p, '2')), '10'); } } } }
function cosinus($x, $iterNum) { $cos = 0; $k = 2; //początkowa wartość dla silni i wykladnka potegi for ($i = 1; $i <= $iterNum; $i++) { $zm = power($x, $k) / factorial($k); //wyliczenie potega/silnia if ($i % 2 == 1) { $zm = $zm * -1; //zmiana znaków co drugi raz } $x += 2; $cos = $cos + $zm; } return $cos + 1; }
function tm($cnt) { global $site; if ($cnt === 'site_logo') { echo $site['site_logo']; } elseif ($cnt === 'site_name') { echo $site['site_name']; } elseif ($cnt === 'power') { power(); } elseif ($cnt === 'title') { if (isset($_SESSION['pagetitle']) and !is_null($_SESSION['pagetitle'])) { echo $_SESSION['pagetitle']; } else { echo $site['site_name']; } } elseif ($cnt === 'footer') { if (is_logged()) { } else { echo 'Copyright © ' . date("Y") . ' ' . $site['name']; } } elseif ($cnt === 'menu') { if (!is_logged()) { echo url('account/login', t('Login')) . " \n"; echo url('account/signup', t('Cadastro')); } else { $qry = mysql_query("SELECT item,url FROM cfg_menu ORDER BY `order`"); echo url("home", t("Home")) . " \n"; if (mysql_num_rows($qry) != 0) { while ($row = mysql_fetch_array($qry)) { echo url($row['url'], t($row['item'])) . " \n"; } } if (is_admin()) { echo url("admin", t("Administração")) . " \n"; } echo url("account/modify", t("Minha conta")) . " \n"; echo url("account/logout", t("Sair")) . " \n"; } } elseif ($cnt === 'content') { echo $_SESSION['swout']; } elseif ($cnt === 'head') { echo $_SESSION['swhead']; } }
function checkpower($p, $T = "Permission_Denied", $url = "admincp.php?do=home") { global $admin; if (is_array($p)) { $__power__ = TRUE; foreach ($p as $__p__) { if (power($__p__)) { $__power__ = FALSE; break; } } } else { $__power__ = !power($p); } if ($__power__) { redirect(lang($T), $url); exit; } }
function power($val, $pow) { if ($pow === 0) { return 1; } elseif ($pow > 0) { return $val * power($val, --$pow); } else { $pow *= -1; return 1 / power($val, $pow); } }
} echo cube(3)."<br>"; echo cube(5)."<br>"; echo cube(2)."<br>"; ?> </p> <p> <?php function power($num, $pow) { return "$num^$pow is ". pow($num, $pow); } echo power(2,3)."<br>"; echo power(3,4)."<br>"; echo power(15,15)."<br>"; ?> </p> <p> <?php function printRandomGreeting($person) { $greetings = array("Hi, ","Hello, ",'How are you, ', 'Nice to meet you '); $k = rand(0,3); return $greetings[$k].$person; } echo printRandomGreeting("Simon"); ?> </p>
} ?> <?php if (power("menu_advertise")) { ?> <li><a href="admincp.php?do=advertise" target="main">广告管理</a></li><?php } ?> <?php if (power("menu_message")) { ?> <li><a href="admincp.php?do=message" target="main">留言管理</a></li><?php } ?> <?php if (power("menu_cache")) { ?> <li><a href="admincp.php?do=cache" target="main">更新缓存</a></li><?php } ?> </ul> </div> <div class="cmain" id="cmain"></div> <div class="cfixbd"></div> </div> <script type="text/JavaScript"> //var headers = new Array('index', 'setting', 'article', 'user', 'database', <?php if ($DreamCMS->config['ishtm']) { ?> 'html',<?php }
<?php /* * DreamArticle Version3.0 * Copyright 2007-2008, iDreamSoft * http://www.idreamsoft.cn * By:coolmoo<*****@*****.**> */ !defined('DCPATH') && exit('What are you doing?'); foreach ($menu_array as $key => $menus) { if (power($key)) { echo '<ul id="menu_' . $key . '" style="display: none">'; foreach ($menus as $k => $url) { if (power($k)) { echo '<li><a id="' . $k . '" href="' . (substr($url, 0, 4) == 'http' ? $url : 'admincp.php?do=' . $url) . '" target="main">' . lang($k) . '</a></li>'; } } echo '</ul>'; } }
/** * Recursive function which accepts 2 parameter, and returns the value of the first parameter to the power of the second. * * @param int $num1 * @param int $num2 * @return int */ function power($num1, $num2) { if ($num2 == 0) { return 1; } if ($num2 == 1) { return $num1; } // echo " return $num1 * power($num1, $num2-1)<br>"; //Debug Info return $num1 * power($num1, $num2 - 1); }
<?php //function hw answers function cube($num) { return $num*$num*$num; } echo cube(3); echo "<br>"; echo cube(9); echo "<br><br>"; function power($num,$to) { $result = 1; for ($k=0; $k<$to; $k++) $result = $result*$num; return $result; } echo power(3,5); echo "<br>"; echo power (2,3); echo "<br><br>"; function pRG($person) { $greetings = array ("hi ", "hello ", "hola "); $index = rand(0, count($greetings)-1); $myGreeting=$greetings[$index]; echo $myGreeting. $person; } ?>
function power($val, $pow) { if ($pow == 0) { return 1; } if ($pow >= 1) { if ($pow == 1) { return $val; } else { return $val * power($val, $pow - 1); } } else { if ($pow < 0) { return 1 / power($val, -$pow); } } }
function power($val, $pow) { $pow = (int) $pow; if (0 == $val) { return 0; } if (0 == $pow) { return 0; } elseif (1 == $pow) { return $val; } elseif (-1 == $pow) { return 1 / $val; } elseif (0 < $pow) { return power($val, $pow - 1) * $val; } elseif (0 > $pow) { return power($val, $pow + 1) / $val; } }
function power($val, $pow) { if ($pow == 0) { return 1; } return $val * power($val, $pow - 1); }