Hehe smart that rocks.
Hehe smart that rocks.
Sorry, the moderator in me couldn't take it anymore, I just had to merge the two threads.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Alright, I'll post mine. Like the 'recursive main' call, mine is recursive also. However, mine is ANSI compatible, and does in fact print 1 to N in order:
There ya go.Code:#include <stdio.h> void ntimes( void ) { static int n = 1; printf("n is %d\n", n ); fflush( stdout ); ntimes( ); } int main( void ) { printf( "This program prints the numbers 1 to N,\n" "where N is the available stack space\n", "divided by the overhead of the call\n", "to the function itself. Hey, you never\n", "set a requirement for N, that's your\n", "own fault.\n" ); ntimes( ); return 0; }
*whistles innocently*
Quzah.
Hope is the first step on the road to disappointment.
the main reason why m=t||exit(0) is used is that till the end number and the current number is not same t is always 1Code:#include<stdio.h> int main() {int n,func1(); printf("enter the value of n"); scanf("%d",&n); func1(n); } int func1(int n) {static int k=1; int t=0; int m; t=k^n; printf("\n%d",k); ++k; m=t||exit(0);/*this is a short circuit operation using or*/ func1(n); }
due to XOR operation so when t is 1 in m=t||exit(0)
compiler does not check the or statement.
so when t is 1 compiler skips exit(0)
and next func1 is called.
once the number n and k become equal t is 0 due to XOR
thus when m=t||exit(0)
is evaluated the second part of the exp is checked and the loop terminates.
Last edited by debuger2004; 06-20-2003 at 12:02 PM.
You didn't prototype func1 (or give it a return type), main returns an int, and what in the heck is this: 'm=t||exit(0);'?
Also, use code tags.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
Also, stop making new threads. Hammer, want to merge this (again!)?Originally posted by XSquared
Also, use code tags.
Your code (after I correct it so it would compile without error) does nothing other than exiting after the first function call. Perhaps you should actually try running your code?
Quzah.
Hope is the first step on the road to disappointment.
You are losing your time is a silly problem.
All solutions that have been posted are for the recycle bin.
This is not a problem - problems have a purpose and a solution. This has neither purpose nor solution.
>You are losing your time is a silly problem
meened "problem"
It certainly does have a purpose. Gets us to think outside the box, exercises the gray cells, and makes us either get behind at work or loose sleep, both are requirements for professional programmers.Originally posted by AProg
You are losing your time is a silly problem.
All solutions that have been posted are for the recycle bin.
This is not a problem - problems have a purpose and a solution. This has neither purpose nor solution.
Also, just because you don't agree with a solutions doesn't mean it's not a solution. Maybe we just haven't hit the proper solution yet
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
Yes, it does have a purpose. Makes you think and use the language in a way most people don't use it. You are more than welcome to not participate if you don't want to.Originally posted by AProg
You are losing your time is a silly problem.
All solutions that have been posted are for the recycle bin.
This is not a problem - problems have a purpose and a solution. This has neither purpose nor solution.
Well, i could only take this "problem" ( oh God what i am saying! ) as a joke.
>Gets us to think outside the box, exercises the gray cells, and makes us either get behind at work or loose sleep, both are requirements for professional programmers.
Nop, you are wrong.
Before some days, someone gave me a chess problem. I troubled my mind too long, i lost my sleeps and i spent most time thinking about that problem. I couldn't find the answer. I was too closed. At a time i thought it was stated wrongly but because i was closed to an answer, i kept trying. Then, that man told me that he had doen a mistake. I was going to kill him! But i didn't. I knew that it was very good experience. It helped me. YES, that wrongly stated "problem" really had that purpose, and it really helped, yet without a solution.
BUT now, you can't do anything which will help the situation. Skim, all C's features, see that nothiing can be done and then meet the obvious. I meen... there is no point in thinking!! The first thought deletes all the others. And i don't think that joke can make you better.
Do whatever you want...
>You are more than welcome to not participate if you don't want to.
Participate to what??? Your joke or your party?!?!
[rant]Bull. I stated an opinion and my opinion is not wrong. You may disagree, that's your decision to make, but to tell me I'm wrong to hold that opinion is very arrogant. As a programmer since the 70's, I have a better grasp of what's useful than someone that's still learning.[/rant]Originally posted by AProg
>Gets us to think outside the box, exercises the gray cells, and makes us either get behind at work or loose sleep, both are requirements for professional programmers.
Nop, you are wrong.
(I obviously dislike being told I'm wrong by someone that's clueless to the realities)
Hmmm, so it was OK once to have a problem you can't solve, but you should never have a second one? Better find a new career (or hobby). Go flip burgers or something. Fewer unsolvable problems exist.Before some days, someone gave me a chess problem. I troubled my mind too long, i lost my sleeps and i spent most time thinking about that problem. I couldn't find the answer. I was too closed....
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
To participate in the conversation, if you don't like it then quit reading this post.Originally posted by AProg
Well, i could only take this "problem" ( oh God what i am saying! ) as a joke.
>You are more than welcome to not participate if you don't want to.
Participate to what??? Your joke or your party?!?!
I think this can be done recursively..........
Isn't it.............. ???
We all are the components of a huge program...... the programmer is always debugging us with His debugger.
>>Nop, you are wrong.
Well, i think it's very obvious, that according to my opinion, your opinion is wrong. I didn't say it's universally ackowledged that Walp is wrong or something like that!
You say that this "problem" makes you think outside the box and blah blah blah and i tell you that NO, this problem won't do something like this, especially for a man who knows very good how to programm, exept if you are a beginner and you are determine to find "the answer", and through your attempt learn all the C. But now, where you know C, it will be just a waste of time.
So yes, ACCORDING TO MY OPINION, your opinion is wrong. Always some opinions are wrong, some others are right. In some cases science can indicate which one is wrong, whereas in some other cases it's just subjective - like this one.
>Hmmm, so it was OK once to have a problem you can't solve, but you should never have a second one?
This second one doesn't requires too much thought to say it's unsolvable. Chess problems aren't the same. You really think. Yes that's the answer. You really think to come to the conclusion that it is unsolvable. Sure, I don't say that there aren't programming problems that require too much thinking to say that they are unsolvable. But the current one is just a silly thought.
>Better find a new career (or hobby). Go flip burgers or something.
Hmmmmm... who's rude now?...
>Fewer unsolvable problems exist
Have a look around you - might help...
>To participate in the conversation, if you don't like it then quit reading this post.
Sure, if i don't like a conservasion i 'll definetely leave