Objective-C :: Aufgabe #32
1 Lösung

99 Bottles of Beer - Selbstständige Lösung
Anfänger - Objective-C
von pocki
- 11.01.2013 um 14:07 Uhr
Programmiere eine eigenständige Lösung zur gängigen Programmier-Übung bzw. Lied 99 Bottles of Beer
Ausgabe:
Ausgabe:
Konsolenausgabe:
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 99 bottles of beer on the wall.
98 bottles of beer on the wall, 98 bottles of beer.
... usw.
Lösungen:

#include <stdio.h> void singTheSong(int numberOfBottles) { if (numberOfBottles == 0) { printf("There are simply no more bottles of beer on the wall.\n"); } else { printf("%d bottles of beer on the wall. %d bottles of beer.\n", numberOfBottles, numberOfBottles); int oneFewer = numberOfBottles - 1; printf("Take one down, pass it around, %d bottles of beer on the wall. \n", oneFewer); singTheSong(oneFewer); // This function calls itself! printf("Put a bottle in the recycling, %d empty bottles in the bin.\n", numberOfBottles); } } int main(int argc, const char * argv[]) { singTheSong(99); return 0; }