Two days ago I was reading in RethinkDB‘s blog the “Will the real programmers please stand up?” which took me to the blogpost of Coding Horror “Why Can’t Programmers.. Program?”.
After reading these two articles I had the idea to start a FizzBuzz coding section just for fun (CfF – Coding for Fun).
So today’s FizzBuzz question is…
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
Below is my solution written in php.
<?php
echo '<h2>Coding For Fun</h2>';
$three = 3;
$five = 5;
$fifteen =15;
for ($i=1; $i<=100; $i++){
if (($i%$three === 0) && ($i%$five === 0)) {
echo 'FizzBuzz<br />';
} elseif ($i%$three === 0) {
echo 'Fizz<br />';
} elseif ($i%$five === 0) {
echo 'Buzz<br />';
} else {
echo $i . '<br />';
}
}
echo '<br />==============<br /><br />';
for ($i=1; $i<=100; $i++){
if ($i%$fifteen === 0) {
echo 'FizzBuzz<br />';
} elseif ($i%$three === 0) {
echo 'Fizz<br />';
} elseif ($i%$five === 0) {
echo 'Buzz<br />';
} else {
echo $i . '<br />';
}
}
?>
Yes… it took me 10 minutes ![]()
Can i stand up?!
read also...
- 30/03/2011 -- Project: Loukoulos.com (2)
- 31/01/2011 -- Wordpress permalinks with Greek/Russian/Arabic characters (10)
- 07/04/2010 -- Cholesterol Levels 2010 (= Greek Easter) (1)
- 07/03/2010 -- Dutch PHP Conference 2010 (0)
- 15/02/2010 -- Track My Weather v.0.5 – Facebook Application (1)
- 20/12/2009 -- 15 Rules to follow for safer web applications (3)
- 15/12/2009 -- Athens StartUp Weekend 2 (0)
- 29/07/2009 -- Track My Weather v.0.1 – Facebook Application (0)
- 01/07/2009 -- PHP 5.3.0 Released! (0)
- 20/06/2009 -- PHP 5.2.10 Released! (0)
bah. stupid striptags.
How would u use with html
Like having 2 files index.htlm and fizzbuzz.php any suggestions.Am new with php
Dave, could you please explain exactly what do you want to do ?!