VN:F [1.6.9_936]
Rating: 5.0/10 (1 vote cast)

I found an interesting problem on net and as a noivce decided to solve it all by self with the help of PHP.
Problem:”If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Solution:
“<?php
for($counter=1; $counter < 1000 ; $counter ++)
{
//echo ”

“;
//echo ”
“.$counter.”–> “;

$int_var1 = ($counter/3); //current counter will be divided by 3
$int_var2 = ($counter/5); //current counter will be divided by 5

$str_type1 = gettype($int_var1); //This will return integer if counter was divided by 3 properly
$str_type2 = gettype($int_var2); //This will return integer if counter was divided by 5 properly

if ($str_type1 == ‘integer’ || $str_type2 == ‘integer’ ) //to check which “counter” was properly divided
{
//echo “This is integer”;
$int_result = $int_result+$counter;

}
else
{
//echo ” NON INTEGER” ;
}
}
echo “Result is: $int_result “;

?>