| | |
Generate 1 to n mumbers.
![]() |
>But there is for loop in it
How do you know? It might be a while loop, or it might even be magic. Coming up with a ridiculous excuse to call a library function is just as reasonable as coming up with a ridiculous requirement of doing something an unknown number of times without any kind of iteration at all.
The way I see it, you only have one good option: Slap the bejeezus out of the person who gave you this assignment and find another teacher. You won't learn anything useful from this assignment that couldn't be learned more easily with something realistic.
How do you know? It might be a while loop, or it might even be magic. Coming up with a ridiculous excuse to call a library function is just as reasonable as coming up with a ridiculous requirement of doing something an unknown number of times without any kind of iteration at all.
The way I see it, you only have one good option: Slap the bejeezus out of the person who gave you this assignment and find another teacher. You won't learn anything useful from this assignment that couldn't be learned more easily with something realistic.
I'm here to prove you wrong.
•
•
Join Date: Oct 2007
Posts: 305
Reputation:
Solved Threads: 43
lol .. I am always amazed by such questions .. there is complex stuff and then there are just idiotic unreasonable expectations and this falls in the latter category.
how on earth do you expect to generate n numbers without using a loop ? Now you could write n assignment statements one below the other ... but really that would not make any sense.
Well to add to this discussion, someone has apparently come up with a mechanism to do something similar .. here. Of course I still think its a convoluted way to trying to get you to do something, which in my opinion, you should never do in practice, but hey, I am not an authority on this stuff.
how on earth do you expect to generate n numbers without using a loop ? Now you could write n assignment statements one below the other ... but really that would not make any sense.
Well to add to this discussion, someone has apparently come up with a mechanism to do something similar .. here. Of course I still think its a convoluted way to trying to get you to do something, which in my opinion, you should never do in practice, but hey, I am not an authority on this stuff.
Last edited by stilllearning; Oct 3rd, 2008 at 6:12 pm.
>Now you could write n assignment statements one below the other
Presumably the requirement is that n is an unknown quantity until runtime, in which case hard coding the statements is not possible in a compiled language. You could write a second program that builds the hard coded statements into a final program, but then you would be back to square one of not using a loop or recursion.
>someone has apparently come up with a mechanism to do something similar .. here
That would be recursion, which isn't allowed. Technically, any solution would involve some kind of loop or some kind of recursion, so unless you word the restrictions in such a way to allow the expected solution, it's quite literally an impossible problem.
A good trick is to use a third party program so that your program technically doesn't contain a loop or recursion. This relies on a common loophole of the program requirements.
Other tricky solutions are hiding the loop with goto, or hiding recursion with process spawning. Yet another is this evil little combination of tricks direct to Daniweb via my sleep deprived brain:
Presumably the requirement is that n is an unknown quantity until runtime, in which case hard coding the statements is not possible in a compiled language. You could write a second program that builds the hard coded statements into a final program, but then you would be back to square one of not using a loop or recursion.
>someone has apparently come up with a mechanism to do something similar .. here
That would be recursion, which isn't allowed. Technically, any solution would involve some kind of loop or some kind of recursion, so unless you word the restrictions in such a way to allow the expected solution, it's quite literally an impossible problem.
A good trick is to use a third party program so that your program technically doesn't contain a loop or recursion. This relies on a common loophole of the program requirements.
Other tricky solutions are hiding the loop with goto, or hiding recursion with process spawning. Yet another is this evil little combination of tricks direct to Daniweb via my sleep deprived brain:
c Syntax (Toggle Plain Text)
// Do not try this at home, kids #include <stdio.h> #include <stdlib.h> int main ( int argc, char *argv[] ) { if ( argc > 1 ) { int n = atoi ( argv[1] ); if ( n > 0 ) { char buf[BUFSIZ]; printf ( "%d\n", n ); sprintf ( buf, "\"%s\" %d", argv[0], n - 1 ); system ( buf ); } } return 0; }
I'm here to prove you wrong.
![]() |
Other Threads in the C Forum
- Previous Thread: Binary (base 2) to Decimal (base 10) HELP!
- Next Thread: Need help with code. returning wrong values, and i cant figure out why
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency function getlasterror getlogicaldrivestrin givemetehcodez graphics gtkgcurlcompiling gtkwinlinux hardware highest histogram homework i/o ide inches initialization intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi






