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.
Example 1 of project Euler using PHP
Here in this article we will discuss about Project Euler example 1
the main logic in this example is in this condition:
if($i % 3 == 0 || $i % 5 == 0){
$sum += $i;
}
Next, I have written a function which will find the sum of all the multiples of 3 and 5 up to 1000,
function sumOf3And5($count)
{
$sum = 0;
for($i=0; $i<$count; $i++)
{
if($i % 3 == 0 || $i % 5 == 0){
$sum += $i;
}
}
echo $sum;
}
echo sumOf3And5(1000);