Thread: Any website suggestion?

  1. #1
    JJ1
    Guest

    Any website suggestion?

    Does anyone have a good website I can go to. I would like to know the difference between recursion and repetition.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Have you looked at the programming tutorials here?

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Tutorial

    A guess would be something like this :
    Code:
    #include <iostream>
    using namespace std;
    
    void recursion(int arg);
    
    int main()
    {
    
        cout << "This is repetition" << endl;
        for (int x=0;x < 6; x++)
            cout << x << endl;
        
        cout << endl << "This is recursion" << endl;
        recursion(5);
    
        system("PAUSE");
    }
    
    void recursion(int arg)
    {
        if (arg > 0)
            recursion(arg-1);
        
        cout << arg << endl;
    }
    Someone please correct me if Im wrong.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    I would like to know the difference between recursion and repetition.
    Recurrison repeats a chunk of code. Repetition runs different chunks of code that are the same.

    Recurrison = good (when necessary)
    Repetition = bad, bad, BAD!

    Understand?

    This is repetition:

    Code:
    cout<<"Hello, world!"<<endl;
    cout<<"Hello, world!"<<endl;
    cout<<"Hello, world!"<<endl;
    cout<<"Hello, world!"<<endl;
    cout<<"Hello, world!"<<endl;
    cout<<"Hello, world!"<<endl;
    Last edited by funkydude9; 07-29-2003 at 02:01 PM.
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  5. #5
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Recursion is a great tool when necessary, but should probably be avoided when there is another (reasonable) way to accomplish the same thing. If the recursion goes more than a few levels deep, overhead incurred from calling the function repeatedly can cause problems. In many cases (not all, of course), recursion can be replaced with a while loop.
    Away.

  6. #6
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    It's also kind of interesting to write an infinately recurring function like:
    Code:
    void func(int x)
    {
         cout << x << endl;
         x++;
         func(x);
    }
    Don't worry, it won't crash your comp! You'll notice that after a certain number of calls your program will terminate, this is because you've used up all the mem you're allowed.

    I hope that's right.

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    249
    few levels deep
    What's a few?
    Well, there are a few things wrong with your code:

    1) It does not work.
    2) It does not work.
    3) It does not work.

    Hope this helps.

  8. #8
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    actually you don't use up memory that your program's been allowed.

    You overflow the stack (its kind the same but not really)
    Every time you call a function it pushes all the vars into the stack and because it calls it self without an end condition the stack gets filled up and then your program exits with a segmentation fault.
    See Stack-Overflow or for a REALLY REALLY good example and explanation of how the stack is/works and how to 'use' it...
    Aleph1's Smashing the Stack for Fun and Prophit
    Also, see pointers and memory in my signature below

    -LC
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How's my new Website
    By asbo60 in forum General Discussions
    Replies: 53
    Last Post: 07-10-2009, 10:10 AM
  2. Yet another website problem...
    By Xterria in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-21-2004, 01:27 AM