Language C
(poor Style)
| Date: | 09/01/05 |
| Author: | Matteo Casati |
| URL: | n/a |
| Comments: | 8 |
| Info: | n/a |
| Score: |
/* The 99 Bottles of Beer Program
*
* Sept. 1st 2005
* by Matteo Casati <devaraja87^gmail^com>
*
* This is the poor-style C version of
* the program. It uses only gotos.
*/
int main()
{
int n_beers=99;
char pl='s';
goto a;
z:
return 0;
b:
n_beers--;
if(n_beers){
pl=(n_beers==1?31:'s');
printf("%d bottle%c of beer on the wall!\n",n_beers,pl);
goto a;
}else{
printf("no more bottles of beer on the wall!\n");
printf("No more bottles of beer on the wall,"
" no more bottles of beer.\nGo to the store"
" and buy some more, 99 bottles of beer on the wall!\n");
goto z;
}
a:
printf("%d bottle%c of beer on the wall, "
"%d bottle%c of beer\n",n_beers,pl,n_beers,pl);
printf("Take one down and pass it around, ");
goto b;
}
Download Source | Write Comment
Alternative Versions
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| Linux kernel module | Stefan Scheler | 08/02/05 | 15 | |
| Correct ANSI C containing no semicolons | Steve Checkoway | 01/15/09 | 0 | |
| multithreaded version | Stefan Scheler | 05/11/05 | 6 | |
| actually produces correct lyrics :P | Dustshine | 08/20/05 | 0 | |
| standard version | Bill Wein | 04/20/05 | 4 |
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
Also:
#include <stdio.h> int main() {However, the program does use string concatenation. Perhaps poorer style might be something like
<pre>
printf("No more bottles of beer on the wall,\
no more bottles of beer.\nGo to the store\
and buy some more, 99 bottles of beer on the wall!\n"
</pre>
And I guess I now know not to put in formatting tags...
Ahh, but int main(), and not returning anything tops both
No. If control "falls off" the end of main() without an explicit return statement, the return value is zero.
how about...
//this WILL compile with gcc
#define P printf
main(){
char i='c',*s="s",*z="",*c=" of beer",*w=" on the wall, ",*b=" bottle",
*n="no more",*t="take one down and pass it around, ";
a:P("%d%s%s%s%s%d%s%s%s\n%s",i,b,i>1?s:z,c,w,i,b,i>1?s:z,c,t);
i<2?P(n):P("%d",i-1);P("%s%s%s%s\n\n",b,i-2?s:z,c,w);
if(--i)goto a;goto b;
b:P("%s%ss%s%s%s%ss%s\ngo to the store and buy some more, 99%ss%s%s\n",
n,b,c,w,n,b,c,b,c,w);
}