Thread: recursive find of the smallest member..

  1. #31
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    Nevermind my previous post.
    edit:
    I slightly overlooked the test cases.
    Last edited by stevesmithx; 01-13-2009 at 09:14 AM.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  2. #32
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i put -1
    on the index of that line
    and i get the same error
    and now the output is not correct
    ??

  3. #33
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    how to fix this out of band problem?

  4. #34
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    Which compiler are you using.
    It compiles and runs fine under mingw port of gcc.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  5. #35
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    You posted this program, and it looks like it should work:
    Code:
    #include <stdio.h>
    int recFindMin(int array[], int index);
    
    int main()
    {
        int array[3] = {2, 1, 3};
    
        printf("%d\n", recFindMin(array, 2));
    
        return 0;
    }
    
    int recFindMin (int array[], int index)
    {
        int local;
        if (index == 0)
        {
            return array[index];
        }
    
        local = recFindMin(array, index - 1);
        if (array[index] > local)
        {
            return local;
        }
        else
        {
            return array[index];
        }
    }
    Do you get any errors running the above program that you wrote? I merely adjusted the indentation and remove the superfluous 100 from the function parameter.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #36
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    thanks its working

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 22
    Last Post: 05-29-2009, 05:44 PM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Replies: 2
    Last Post: 09-05-2004, 07:13 AM
  4. Builder 5 v's bcc32.exe
    By sononix in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2004, 10:17 AM
  5. How do I base size of arrays on annother number?
    By Dual-Catfish in forum C++ Programming
    Replies: 15
    Last Post: 09-25-2001, 01:31 PM