Skip to content

Instantly share code, notes, and snippets.

@avinashdexterous
Forked from tchalvak/cakepi.php
Created December 20, 2012 14:26
Show Gist options
  • Save avinashdexterous/4345569 to your computer and use it in GitHub Desktop.
Save avinashdexterous/4345569 to your computer and use it in GitHub Desktop.
<?php
/*
Using php, write a program that must fulfill these requirements:
For the numbers from 1 to 100,
If the number is a multiple of 3, print cake instead of the number.
If the number is a multiple of 5, print pi instead of the number.
If the number is a multiple of 15, print cakepi instead of the number.
Otherwise, print the number itself.
Each number's output should be followed by a new line.
*/
for($i=1;$i<=100;$i++){
if($i%15==0){
echo "cakepi<br/>";
}elseif($i%3==0){
echo "cake<br/>";
}elseif($i%5==0){
echo "pi<br/>";
}else{
echo $i."<br/>";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment