Science Fair Project Encyclopedia
99 Bottles of Beer computer program
A 99 Bottles of Beer computer program is a common programming exercise. The idea is to program a routine writing out the full lyrics of "99 Bottles of Beer".
Example in C++:
int main() {
int i;
for(i = 99; i > 0; --i) {
cout i << " bottles of beer on the wall\n";
cout i << " bottles of beer!\n";
cout "Take one down, pass it around. " << (i-1) << " bottles of beer on the wall!\n";
}
return 0;
}
perl -e '$b="of beer";$w="on the wall";print "$_ ",b($_)," $b $w\n$_ ",b($_)," $b\ntake one down, pass it around, ",$_-1," ",b($_-1)," $b $w\n\n" foreach (reverse 1..99);sub b{$x="bottle";$_[0]==1?$x:$x."s";}'
Example in PHP:
<?PHP
for($I = 99; $I > 0; $I--)
{
echo $I . " bottles of beer on the wall!\n";
echo $I . " bottles of beer!\n";
echo "Take one down, pass it around. " . ($I - 1) . " bottles of beer on the wall!\n\n";
}
?>
Related topics
External links
10-26-2009 08:16:03
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details


