![]() |
| | #1 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| C++ challenge: Sum of numbers This challenge is C++ only. If you can solve it in C, I will be extremely impressed, though. Challenge: Write a program which reads integer values from standard input until EOF, then displays their sum on standard output. Do not worry about overflow. The Goofy Part: Your program must contain EXACTLY ONE SEMICOLON. If you choose to "return 0;" at the end of main(), that semicolon does not count. You may, and most likely will, use any and all features of standard C++ including STL. Last edited by brewbuck; 10-12-2007 at 11:29 AM. |
| brewbuck is offline | |
| | #2 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #3 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| |
| brewbuck is offline | |
| | #4 |
| Deathray Engineer Join Date: Mar 2007
Posts: 3,211
| Just read in number after number and print their sum, and we can only use one semicolon (outside of the return from main())? Mmkay. I managed to do it in C as far as I can understand the rules. I can do it without any semicolons, but I think I have undefined behavior in my program. Moving it to only one semicolon, and I believe it to be valid, if not incredibly stupid, C. Should I send it to you via PM or post it here? Be forewarned, it's pretty ugly.
__________________ |
| MacGyver is offline | |
| | #5 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Ah well, decided to give it a try, and it was simpler than I thought. So yeah, by PM, or post here?
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #6 |
| Registered User Join Date: Jan 2005
Posts: 7,137
| Cool idea. I've got a solution that works in VC++ 7.1. |
| Daved is offline | |
| | #7 | ||
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Quote:
Quote:
| ||
| brewbuck is offline | |
| | #8 | |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Quote:
Now, imagine an entire program written in this style. That's how I write C++ :-P | |
| brewbuck is offline | |
| | #9 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #10 | |
| Deathray Engineer Join Date: Mar 2007
Posts: 3,211
| PM sent. Quote:
__________________ | |
| MacGyver is offline | |
| | #11 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Laserlight, MacGyver, and Daved -- good stuff so far. I'm glad this isn't as obscure as I feared. And no MacGyver, I don't refer to THAT when I say I code like that all the time |
| brewbuck is offline | |
| | #12 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #13 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| |
| brewbuck is offline | |
| | #15 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Okay, okay. Basically, the fellow (I think that's literally his academic designation, Senior Fellow) used some plagiarism detection software that detected that several people submitted similiar programs for an assignment (which was, ironically, about detecting software similiarity). I was told that my program matched too closely that of a student who I have never met in any way. That student supposedly collaborated with five other students, but strangely my program was not deemed to have been similiar enough to their programs to be matched. My reasoning is that I must have used telepathy or something to communicate, since I clearly never met the student in person, on a forum, by email, phone, etc. As such, we were psychics who cheated with our special abilities. Anyway, it turned out that the plagiarism detection software had been fooled by the fact that we had adopted a similiar approach to solving the problem, one that involved breaking it down to several small functions in an already small program. So, despite our different naming schemes and styles, the software still decided that we were cheating and then trying to hide it by making minor name alterations.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with programming assignment, please! | xMEGANx | C++ Programming | 2 | 02-16-2008 05:29 PM |
| Finding the sum of even numbers using arrays | Fox101 | C Programming | 7 | 12-03-2007 02:20 PM |
| Help With Stacks | penance | C Programming | 7 | 10-09-2005 02:47 PM |
| adding odd numbers only | CheyenneWay | C++ Programming | 12 | 05-06-2004 12:22 AM |
| A (complex) question on numbers | Unregistered | C++ Programming | 8 | 02-03-2002 06:38 PM |