echo "6 - ".checkNumber(6)."\n\n";
echo "9 - ".checkNumber(9)."\n\n";
echo "12 - ".checkNumber(12)."\n\n";

function checkNumber($num) {
	$res = 'Deficient';

	if ($num == 1) {
		return false;
	}

	$sqrt = sqrt($num);

	$sum = 1;
	// Loops starting 2 to the square root of the given number
	for ($i = 2; $i <= $sqrt; $i++) {
		if ($num%$i == 0) {
			$sum += $i;

			$result = $num/$i;
			// If $i is not equal to the square root,
			// then adds it to the $sum variable
			if ($result != $i) {
				$sum += $result;
			}
		}
	}
	if ($sum == $num) {
		$res = 'Perfect';
	} else if ($sum > $num) {
		$res = 'Abundant';
	}
	return $res;
}
by ვაჟა ტყემალაძე
2 years ago
PHP
Problem Solving
php
Note
Problem
0
Pro tip: use ```triple backticks around text``` to write in code fences