|
Fri, Jun 01, 2007
![[Link]](http://geekblog.oneandoneis2.org/img/chain_link.gif)
...when you start working out how to make a program to output the "10 green bottles" song.
(That's the UK equivalent of the "bottles of beer" song, if you're American)
And you know you're REALLY bored when you look up the bash codes so the word "green" is coloured green.
Dread to think what I'll do to it next.
Friday afternoons, eh?
#include <stdio.h>
#define StartNum 10
void bottlenum(int i);
int main()
{
int i = StartNum;
while (i > 0)
{
/* Start only the first verse with the "There were" line */
if (i == StartNum)
{
printf("There were ");
bottlenum(i);
}
bottlenum(i);
printf("And if one \e[32mgreen\e[0m bottle should accidentally fall\nThere'd be ");
bottlenum(--i);
}
return 0;
}
/* This function prints the repetitive part of the song */
void bottlenum(int i)
{
printf("%d \e[32mgreen\e[0m bottle", i);
if (i > 1)
putchar('s');
printf(", sitting on the wall\n");
}
| Mon | Tue | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|
| << < | > >> | |||||
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |