np@doc.ic.ac.uk.UUCP (Nigel Perry) (12/11/87)
[This program deserves at least an Honorable Mention in the Obfusticated C Code Contest! ++bsa] Here is a piece of Christmas trivia, just compile and run - then read the source! I'm posting this for Mike (m.smith@uk.ac.crc) who isn't on usenet, praise to him, flames to me for posting it. Enjoy. --- cut here --- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # partridge.c # partridge.h # This archive created: Mon Nov 30 17:24:39 1987 export PATH; PATH=/bin:$PATH if test -f 'partridge.c' then echo shar: will not over-write existing file "'partridge.c'" else cat << \SHAR_EOF > 'partridge.c' /* Based on an original program written in Algol 68 by John P. Baker University of Bristol. (1978) */ #include "partridge.h" int christmas; long x; main() { printf("Enter a number between 1 and 12 "); scanf("%d",&christmas); if (christmas == 0) christmas = 1; if ((christmas < 0) || (christmas >12)) { printf("Invalid number\n"); exit(); } printf("Factorial of %d is ",christmas); The first day of christmas my true love sent to me A partridge in a pear tree The second day of christmas my true love sent to me Two turtle doves and A partridge in a pear tree The third day of christmas my true love sent to me Three french hens Two turtle doves and A partridge in a pear tree The fourth day of christmas my true love sent to me Four colly birds Three french hens Two turtle doves and A partridge in a pear tree The fifth day of christmas my true love sent to me Five gold rings Four colly birds Three french hens Two turtle doves and A partridge in a pear tree The sixth day of christmas my true love sent to me Six geese laying Five gold rings Four colly birds Three french hens Two turtle doves and A partridge in a pear tree The seventh day of christmas my true love sent to me Seven swans swimming Six geese laying Five gold rings Four colly birds Three french hens Two turtle doves and A partridge in a pear tree The eighth day of christmas my true love sent to me Eight maids milking Seven swans swimming Six geese laying Five gold rings Four colly birds Three french hens Two turtle doves and A partridge in a pear tree The ninth day of christmas my true love sent to me Nine drummers drumming Eight maids milking Seven swans swimming Six geese laying Five gold rings Four colly birds Three french hens Two turtle doves and A partridge in a pear tree The tenth day of christmas my true love sent to me Ten pipers piping Nine drummers drumming Eight maids milking Seven swans swimming Six geese laying Five gold rings Four colly birds Three french hens Two turtle doves and A partridge in a pear tree The eleventh day of christmas my true love sent to me Eleven ladies dancing Ten pipers piping Nine drummers drumming Eight maids milking Seven swans swimming Six geese laying Five gold rings Four colly birds Three french hens Two turtle doves and A partridge in a pear tree The twelfth day of christmas my true love sent to me Twelve lords leaping Eleven ladies dancing Ten pipers piping Nine drummers drumming Eight maids milking Seven swans swimming Six geese laying Five gold rings Four colly birds Three french hens Two turtle doves and A partridge in a pear tree } SHAR_EOF fi # end of overwriting check if test -f 'partridge.h' then echo shar: will not over-write existing file "'partridge.h'" else cat << \SHAR_EOF > 'partridge.h' /* Header file for partridge program. */ #define Two x #define Three x #define Four x #define Five x #define Six x #define Seven x #define Eight x #define Nine x #define Ten x #define Eleven x #define Twelve x #define twelfth 12 #define eleventh 11 #define tenth 10 #define ninth 9 #define eighth 8 #define seventh 7 #define sixth 6 #define fifth 5 #define fourth 4 #define third 3 #define second 2 #define first 1 #define The if ( #define day == #define of #define my ) { #define true x #define love = #define sent 0L #define to ; #define me ++x; #define A #define and #define partridge printf( #define in "%ld\n", #define a #define pear x #define tree );} #define lords *= #define ladies *= #define pipers *= #define drummers *= #define maids *= #define swans *= #define geese *= #define gold *= #define colly *= #define french *= #define turtle *= #define leaping 12L; #define dancing 11L; #define piping 10L; #define drumming 9L; #define milking 8L; #define swimming 7L; #define laying 6L; #define rings 5L; #define birds 4L; #define hens 3L; #define doves 2L; SHAR_EOF fi # end of overwriting check # End of shell archive exit 0 --- cut here --- --- Nigel Perry Department of Computing Imperial College Janet: np@uk.ac.ic.doc London DARPA: np%uk.ac.ic.doc@ucl-cs SW7 Uucp: np@icdoc.UUCP, ukc!icdoc!np England