Generate 1 to n mumbers.

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 16
Reputation: san_sarangkar is an unknown quantity at this point 
Solved Threads: 0
san_sarangkar san_sarangkar is offline Offline
Newbie Poster

Generate 1 to n mumbers.

 
0
  #1
Oct 3rd, 2008
Hi every body , I got one problem that how can we generate 1 to n numbers without using any loop and without using recursion function ?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,805
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Generate 1 to n mumbers.

 
1
  #2
Oct 3rd, 2008
There's a generate_n function in the <algorithm> header.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 16
Reputation: san_sarangkar is an unknown quantity at this point 
Solved Threads: 0
san_sarangkar san_sarangkar is offline Offline
Newbie Poster

Re: Generate 1 to n mumbers.

 
0
  #3
Oct 3rd, 2008
But there is for loop in it but program should not contain any loop.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,042
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 178
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Generate 1 to n mumbers.

 
0
  #4
Oct 3rd, 2008
Originally Posted by san_sarangkar View Post
But there is for loop in it but program should not contain any loop.
Let me tell you a secret, every thing deep inside of the machine, are loops and go to.
Use a search engine, that question is all over, even when I don't understand the profit of it.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,805
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Generate 1 to n mumbers.

 
1
  #5
Oct 3rd, 2008
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 305
Reputation: stilllearning has a spectacular aura about stilllearning has a spectacular aura about 
Solved Threads: 43
stilllearning stilllearning is offline Offline
Posting Whiz

Re: Generate 1 to n mumbers.

 
0
  #6
Oct 3rd, 2008
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.
Last edited by stilllearning; Oct 3rd, 2008 at 6:12 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,805
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Generate 1 to n mumbers.

 
1
  #7
Oct 4th, 2008
>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:
  1. // Do not try this at home, kids
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main ( int argc, char *argv[] )
  6. {
  7. if ( argc > 1 ) {
  8. int n = atoi ( argv[1] );
  9.  
  10. if ( n > 0 ) {
  11. char buf[BUFSIZ];
  12.  
  13. printf ( "%d\n", n );
  14. sprintf ( buf, "\"%s\" %d", argv[0], n - 1 );
  15. system ( buf );
  16. }
  17. }
  18.  
  19. return 0;
  20. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,042
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 178
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Generate 1 to n mumbers.

 
0
  #8
Oct 4th, 2008
>Yet another is this evil little combination of tricks direct to Daniweb via my sleep deprived brain
Could that be the reason that you even entertained the post?
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC