Saturday 29 June 2013

Amstrong in php

<html>
<head>
<title></title>
</head>
<body>
<?php
function amstrong($n,$m,$sum=0,$r)
{
$n=111;
$m=$n;
while($n!=0)
{
$r=$n%10;
$sum=$sum+$r*$r*$r;
$n=$n/10;
}
if($m==$sum)
{
echo "<h1><font color='green'>amatrong</font></h1>";
}
else
{
echo "<h1><font color='red'>not amstrong</font></h1>";
}
}return amstrong($n,$m,$sum,$r);
?>
</body>
</html>

No comments:

Post a Comment