Dzisiaj jest 12 lipca 2025 r.
Chcę dodać własny artykuł
Reklama

99 Bottles of Beer

Chcę dodać własny artykuł

„99 Bottles of Beer”

„99 Bottles of Beer” to popularna angielska piosenka, często wykonywana podczas długich podróży, mająca na celu umilenie czasu. Tekst piosenki polega na stopniowym redukowaniu liczby butelek piwa, zaczynając od 99. Każda zwrotka różni się jedynie liczbą butelek, aż do momentu, gdy pozostaje jedna butelka, a następnie brak butelek.

Ostatnia zwrotka piosenki może brzmieć:

No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall.

Przykłady implementacji w różnych językach programowania

Pascal


uses crt;
var
a:integer;
begin
a:=99;
repeat
write(a);
write(’ bottles of beer on the wall, ’);
write(a);
write(’ bottles of beer. Take one down and pass it around – ’);
a:=a-1;
write(a);
writeln(’ bottles of beer on the wall.’);
until a=2;
writeln(’2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around – 1 bottle of beer on the wall.’);
writeln(’1 bottle of beer on the wall, 1 bottle of beer. Take it down and pass it around – no more bottles of beer on the wall.’);
repeat until keypressed;
end.

C++


#include
using namespace std;
int main()
{
int x = 99;
while (x > 0)
{
if (x > 2)
{
cout << x << " bottles of beer on the wall, " << x << " bottles of beer. " << "Take one down and pass it around - " << x - 1 << " bottles of beer on the wall.\n"; } else if (x == 2) { cout << x << " bottles of beer on the wall, " << x << " bottles of beer. " << "Take one down and pass it around - " << x - 1 << " bottle of beer on the wall.\n"; } else { cout << x << " bottle of beer on the wall, " << x << " bottle of beer. " << "Take one down and pass it around - no more bottles of beer on the wall.\n"; } x--; } }

C#


void Main(){
for (int i = 99; i > 1; i–){
Console.WriteLine(i + ” bottles of beer on the wall, ” + i + ” bottles of beer. Take one down and pass it around – ” + (i – 1) + ” bottles of beer on the wall.”);
}
Console.WriteLine(„1 bottle of beer on the wall, 1 bottle of beer. Take it down and pass it around – no more bottles of beer on the wall.”);
}

Python


for i in range(99, 0, -1):
if i == 1:
print(’1 bottle of beer on the wall, 1 bottle of beer!’)
print(’So take it down, pass it around, no more bottles of beer on the wall!’)
elif i == 2:
print(’2 bottles of beer on the wall, 2 bottles of beer!’)
print(’So take one down, pass it around, 1 bottle of beer on the wall!’)
else:
print(f'{i} bottles of beer on the wall, {i} bottles of beer!’)
print(f’So take it down, pass it around, {i – 1} bottles of beer on the wall!’)

JavaScript


function bottlesOfBeer() {
for (let i = 99; i >= 0; i–) {
var lasts = i – 1;
if (i == 2) {
console.log(i + ” bottles of beer on the wall, ” + i + ” bottles of beer. Take one down and pass it around – ” + lasts + ” bottle of beer on the wall.”);
} else if (i == 1) {
console.log(i + ” bottle of beer on the wall, ” + i + ” bottle of beer. Take it down and pass it around – no more bottles of beer on the wall.”);
} else if (i == 0) {
console.log(„No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall.”);
} else {
console.log(i + ” bottles of beer on the wall, ” + i + ” bottles of beer. Take one down and pass it around – ” + lasts + ” bottles of beer on the wall.”);
}
}
}