Language B
(Ken Thompson's B, predecessor to C)
Date: | 08/21/06 |
Author: | Pietro Gagliardi |
URL: | http://www.andlabs.com/ |
Comments: | 3 |
Info: | http://cm.bell-labs.com/cm/cs/who/dmr/kbman.html |
Score: | ![]() |
/* 99 Bottles of Beer B Version By Pietro Gagliardi Started and Completed August 21, 2006 Try this if you can access a 1st edition Unix! :-) */ main() { auto a; while (a >= 0) { printf("%d %s of beer on the wall!*n", a, (a == 0 ? "bottle" : "bottles")); printf("%d %s of beer,*n", a, (a == 0 ? "bottle" : "bottles")); printf("You take one down, pass it around,*n"); if (a == 0) break; printf("%d bottles of beer on the wall!*n*n", --a); } printf("No more bottles of beer on the wall!*n"); }
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
I don't have a 1st edition Unix, nor any later 1, but...
DOES THIS WORK ?
It looks like "1 bottles" and "0 bottle" to me,
although it will "break" before it ever uses "0 bottle" !
And does "auto a" start at 99 ?
/* Is 99 snatched from within the comment ?
It would probably be better if this program would not be
completed within one day.
I found it when there were only 997 variations of
99-bottles-of-beer. Somehow Oliver Shade suddenly counted
1000 without any new additions. There must be a lot of
beer involved here...
But not in B : When the one-thousand celebrations reach
a high there is no replenishing by "going to the store" !
Nonetheless, congratulations with 1000, I like this site !
Han ten Have (Bidnija, Malta)
P.S. For a clear description of full 99-logic see the
dedicated intermediate language in my DEBUG version of 99.
It could be implemented with any Turing-complete language
although mine is not.
/* 99 Bottles of Beer
B Version
By Pietro Gagliardi
Started and Completed August 21, 2006
Try this if you can access a 1st edition Unix!
main()
{
auto a;
a = 99;
while (a >= 0) {
printf("%d %s of beer on the wall!*n", a, (a == 0 ? "bottle" : "bottles"
printf("%d %s of beer,*n", a, (a == 0 ? "bottle" : "bottles"
printf("You take one down, pass it around,*n"
if (a == 0) break;
printf("%d bottles of beer on the wall!*n*n", --a);
}
printf("No more bottles of beer on the wall!*n"
}