Here I want to share my experience at that time I was working as a programmer php test and given the matter as follows:
Make a 1-100 number series and each multiple of three figures were changed "ding", each multiple 5 change "dong", and any change multiple 3 & 5 "dingdong".
and here's the answer:
<?php
for($i=1; $i<=100; $i++){
if($i%3==0 && $i%5==0){
echo "dingdong";
}
else if($i%3==0){
echo "ding";
}
else if($i%5==0){
echo "dong";
}
else{
echo $i;
}
}
?>
for($i=1; $i<=100; $i++){
if($i%3==0 && $i%5==0){
echo "dingdong";
}
else if($i%3==0){
echo "ding";
}
else if($i%5==0){
echo "dong";
}
else{
echo $i;
}
}
?>
for ($ i = 1; $ i <= 100; $ i ++); // useful to make a sequence of numbers 1-100
if ($ i% 3 == 0); // mean if i (1) multiple (%) 3 echo "ding" will feature characters ding //
if ($ i% 5 == 0); // mean if i (1) multiple (%) 5, echo "dong" will display the character dong //
if ($ i% 3 == 0 && $ i% 5 == 0); // mean if i (1) multiple (%) 3 & 5, echo "dingdong" dingdong character // will display
the results:
If you have any questions please comment.
Do not forget to like and share.
Bejar Programming in fajaryusuf.com wrote. :)
Comments