PHP Practical Slip 4 Q.B

Write a PHP Script to display a perfect numbers between 1 to100.

<?php
for ($num = 1; $num <= 100; $num++) {
    $sum = 0;

    for ($i = 1; $i < $num; $i++) {
        if ($num % $i == 0) {
            $sum += $i;
        }
    }

    if ($sum == $num && $num != 0) {
        echo $num . " is a Perfect Number.<br>";
    }
}
?>

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top