C :: Aufgabe #32
3 Lösungen
99 Bottles of Beer - Selbstständige Lösung
Anfänger - 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:
/* bottles.c devnull,18-07-2013 */
#include <stdio.h>
#define BB1 "bottle of beer"
#define BOB "bottles of beer"
#define OTW "on the wall"
#define TOD "Take one down and pass it around"
#define GTS "Go to the store and buy some more"
/* main */
int main()
{
int n;
for (n=99;n>0;n--) {
printf("%d %s %s, %d %s.\n",n,(n==1)?BB1:BOB,OTW,n,(n==1)?BB1:BOB);
printf("%s, %d %s %s.\n",TOD,n-1,(n==2)?BB1:BOB,OTW);
}
printf("No more %s %s, no more %s.\n",BOB,OTW,BOB);
printf("%s, 99 %s %s.\n",GTS,BOB,OTW);
return 0;
}
Welch Fummelei mit der Grammatik :D
C-Code
#include <stdio.h>
#include <conio.h>
void main(){
for(int i = 99; i > 0; i--){
printf("%i%s bottle%s of beer on the wall, %i%s bottle%s of beer.\nTake one down and pass it around, ", i, i == 1 ? " last": "", i > 1 ? "s" : "", i, i == 1 ? " last" : "", i > 1 ? "s" : "");
printf(i == 1 ? "no more" : "%i", i-1);
printf("%s bottle%s of beer on the wall.\n\n", i-1 == 1 ? " last" : "", i-1 == 1 ? "" : "s");
}
_getch();
}
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i;
for (i=99;i>0;i--) {
if (i==1)
printf("%d bottle of beer on the wall, %d bottle of beer.\nTake one down and pass it around, %d bottle of beer.\n\n",i,i,i);
else
printf("%d bottles of beer on the wall, %d bottles of beer.\nTake one down and pass it around, %d bottles of beer.\n\n",i,i,i);
}
return EXIT_SUCCESS;
}
