Main-recursion, Mr D. Always fun and good practice and with commandline parameters use argc as your variable.
Main-recursion, Mr D. Always fun and good practice and with commandline parameters use argc as your variable.
But then it doesn't compile as C++, Mr. T.
Very well, if you insist, here's one version. I have a sneaking suspicion that it's very similar to a solution that someone's already posted.
Code:#include <stdio.h> int main(int argc, char *argv[]) { while(--argc) {} if(scanf("%i", &argc) == 1) { if(argc += main(0, 0)) {} } if(argv && printf("%i\n", argc)) {} return argc; }
Last edited by dwks; 10-13-2007 at 03:29 PM.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Since this is a contest, shouldn't there be a winner?
I vote me
Sorry guys, I was out of the house for the weekend.
I'm glad my specific wording turned this into a somewhat more interesting affair. I initially considered asking that only a single statement be used, not a single semicolon, but that seemed to give too much freedom. It's easy to chain expressions using comma in a statement-like way and that isn't what I wanted to see.
I thought, if I allow only a single semicolon, that will eliminate at the very least the use of for(; and do while(); but it didn't eliminate while-loops or if-statements. On the other hand if I explicitly disallowed all looping constructs I was afraid I would get a homogeneous set of solutions and that would turn the contest into a math exercise (what's 2 + 2? There's only one right answer).
However I did not imagine that someone would "#define SEMICOLON ;" and use it that way. Definitely within the rules, though.
So the award for Best Abuse Of The Rules goes to zacs7.
The award for Doing What I Did goes to Laserlight for being the first one to land it in my Inbox -- but other people were right behind.
Best Abuse Of Pointers goes to MacGyver.
And everybody gets the Politically Correct Self-Esteem-Preserving Consolation And Fuzzy-Wuzzy Prize.
I would just like to thank my friends, and the people that encouraged me to write crappy, non-conforming code. It's you people that have a part in this award, and I think you all should be proud of your part.
I would name everyone, but time (space?) does not permit, so I shall just say, "Thanks again". Thanks again.