programming-examples/php/Basics/PHP program to get the Hamming numbers upto a given numbers also check whether a given number is a Hamming number..php

41 lines
665 B
PHP
Raw Permalink Normal View History

2019-11-18 14:44:36 +01:00
<?php
function is_hamming_numbers($x)
{
if ($x == 1)
{
return "Hamming Number";
}
if ($x % 2 == 0)
{
return is_hamming_numbers($x/2);
}
if ($x % 3 == 0)
{
return is_hamming_numbers($x/3);
}
if ($x % 5 == 0)
{
return is_hamming_numbers($x/5);
}
return "Not a Hamming Number";
}
function hamming_numbers_sequence($x)
{
if ($x == 1)
{
return "Hamming Number";
}
hamming_numbers_sequence($x-1);
if (is_hamming_numbers($x) == "Hamming Number")
{
echo($x).",";
}
}
print_r(is_hamming_numbers(7)."\n");
print_r(is_hamming_numbers(1)."\n");
hamming_numbers_sequence((24).("\n"));
?>