Thread: question ?

  1. #16
    .........
    Join Date
    Nov 2002
    Posts
    303
    Hehe smart that rocks.

  2. #17
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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]

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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:
    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;
    }
    There ya go.

    *whistles innocently*

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #19
    Registered User
    Join Date
    Jun 2003
    Posts
    21

    code for the first program about printing numbers w/o loops test control structures

    Code:
    #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);
    }
    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 1
    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.

  5. #20
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    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

  6. #21
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by XSquared
    Also, use code tags.
    Also, stop making new threads. Hammer, want to merge this (again!)?

    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.

  7. #22
    Banned
    Join Date
    May 2003
    Posts
    124
    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.

  8. #23
    Banned
    Join Date
    May 2003
    Posts
    124
    >You are losing your time is a silly problem
    meened "problem"

  9. #24
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    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.
    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.

    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

  10. #25
    Registered User
    Join Date
    Oct 2002
    Posts
    385
    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.
    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.
    Wandering aimlessly through C.....

    http://dbrink.phpwebhosting.com

  11. #26
    Banned
    Join Date
    May 2003
    Posts
    124
    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?!?!

  12. #27
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    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.
    [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]
    (I obviously dislike being told I'm wrong by someone that's clueless to the realities)

    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....
    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.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  13. #28
    Registered User
    Join Date
    Oct 2002
    Posts
    385
    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?!?!
    To participate in the conversation, if you don't like it then quit reading this post.
    Wandering aimlessly through C.....

    http://dbrink.phpwebhosting.com

  14. #29
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    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.

  15. #30
    Banned
    Join Date
    May 2003
    Posts
    124
    >>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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM