Created
November 15, 2012 16:20
-
-
Save myinitialsaretk/4079479 to your computer and use it in GitHub Desktop.
I can't believe somebody actually asked me to solve fizzbuzz.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pre> | |
<?php | |
/* | |
FizzBuzz Solution | |
----------------- | |
Write a program that prints out the numbers from A through B, but… | |
For numbers that are multiples of 3, print “Fizz” instead of the number. | |
For numbers that are multiples of 5, print “Buzz” instead of the number | |
For numbers that are multiples of both 3 and 5, print “FizzBuzz” instead of the number. | |
*/ | |
define("A",1); | |
define("B",100); | |
function is_multiple_of_n($integer, $n) | |
{ | |
return ($integer % $n == 0); | |
} | |
for($i = A; $i <= B; $i++) | |
{ | |
$output = ''; | |
if ( !is_multiple_of_n($i,3) && !is_multiple_of_n($i,5) ) | |
{ | |
$output .= $i; | |
} | |
else | |
{ | |
if ( is_multiple_of_n($i,3)) | |
{ | |
$output .= "Fizz"; | |
} | |
if ( is_multiple_of_n($i,5)) | |
{ | |
$output .= "Buzz"; | |
} | |
} | |
echo $output . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment