How many multiple 5 is in 25 using php [closed]

Clash Royale CLAN TAG#URR8PPP
How many multiple 5 is in 25 using php [closed]
Please am looking for a code or php function that can help me know how many 5 is in 25
the code below only returns 5,10,15,20
i want something that will tell 4 instead of breaking the division point
thanks in advance
for($i = 1; $i < 25; $i++)
if ($i % 5 == 0)
echo $i;
;
This question appears to be off-topic. The users who voted to close gave this specific reason:
echo 25 / 5;
@LawrenceCherone Their issue is a programmatical one, not general knowledge of the number of 5s in 25. E.g. the
for statement will stop when reaching "25" and this won't count the final set of 5s. This is a genuine programming error and is answerable.– James
Aug 13 at 1:08
for
2 Answers
2
The reason is you limit your loop to stop when it hits 25. It will only loop when value is less than 25, so as soon as it reaches 25 it wont loop and so wont get your final set of 5s.
Try this:
for ($i = 1; $i <= 25; $i++)
if ($i % 5 == 0)
echo $i;
;
isn't this just a simple division (25%5=5)?
the reason why your code gives your 4 is because you are actually not getting to 25 (the loop stops when i=25), if you will usefor($i=0;$i<=25;$i++) the loop will still run when I=25, and so it will show you 5.
for($i=0;$i<=25;$i++)
Check your math, there is 5, 5's in 25 not 4, also confused as to why your not simply doing
echo 25 / 5;– Lawrence Cherone
Aug 13 at 0:40