Sunday, August 5, 2012

Program For Perfect Number

Here is a Simple PHP program to check whether the given number is Perfect or Not.

1) Below in an Html Form to Enter the Number.

     <html>
<head>
<title>PERFECT NUMBER</title>
</head>
<body>
<form name="perfect" method="GET" action="perfect.php">
<table width="100%" cellpadding="0" cellspacing="0" >
<tr>
<td>
<fieldset>
<ol>
    <li>
        <label>ENTER THE NUMBER:</label>
        <input type="text" name="Num" value=" ">
    </li>
    <li>
        <input type="submit" name="calculate" value="submit"><br>
    </li>
</ol>
</fieldset>   
</td>
</tr>
</table>
</form>
</body>
</html>


2) Below is the Perfect .php

          <?PHP
$n=$_GET['Num'];
for($i=2,$sum=1;$i<$n;$i++)
{
   if($n%$i==0)
     $sum=(int)$sum+$i;
}
if($sum==$n)
  echo"      ENTERED NO. $n IS PERFECT";
else
  echo"      ENTERED NO. $n IS NOT PERFECT";  
?>

No comments:

Post a Comment

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...