Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 516969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:47:09+00:00 2026-05-13T07:47:09+00:00

#include <iostream> using namespace std; int recursiveMinimum(int [], int n); int main () {

  • 0
#include <iostream>
using namespace std;

int recursiveMinimum(int [], int n);

int main () 
{
    int theArray[3] = {1,2,3};

    cout << recursiveMinimum(theArray, 0);
    cout << endl;
    return 0;
}


// pass in array and 0 to indicate first element
// returns smallest number in an array
int recursiveMinimum (int anArray[], int n) // nth element is smallest element in anArray
{
    while (anArray[n+1] != NULL)
    {
        int smallest = n;
        if (anArray[n+1] <= anArray[n])
            smallest = n + 1;
        //if last element has not been reached
        return recursiveMinimum(anArray, smallest);
    }
}

My function exits, but it doesn’t return anything. I tried to set the base case to when the outside of the array is reached. The return 0 line in main is reached so I’m pretty sure the base case in my function is being reached.

Here is the working function:

#include <iostream>
using namespace std;

 int recursiveMinimum(int a[],int min,int index,int size);

int main()
{
    int a[6] = {8, 2, 55, 3, 11, 9};
    cout << recursiveMinimum(a,a[0],1,6) << endl;
    return 0;
}

// pass in the array, the first element, 
// 1 to indicate 2nd element, and the number of elements
int recursiveMinimum(int a[],int min,int i,int size)
{
    if(i == size )
       return min;

    else if(i < size)
    {
       if(a[i] < min)    
          recursiveMinimum(a,a[i], i + 1, size);
       else 
          recursiveMinimum(a,min, i + 1, size);      
    }

}

Thank you to everyone who helped. Due to time constraints I sent out a SOS (Stack Overflow distress Signal), however next time I will definitely step through the debugger prior to asking a question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:47:10+00:00Added an answer on May 13, 2026 at 7:47 am

    You are recursing within the while loop:

    while( condition )
    recursive call
    while( condition )
    recursive call
    .
    .
    .

    Instead what you probably were thinking was

    if( condition )
    recursive call
    recursive call
    recursive call

    you see? Get rid of the while and replace it with an “if” statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <iostream> using namespace std; int main() { cout << !!!Hello World!!! << endl;
#include <iostream> using namespace std; int main (void) { cout << 1\t2\t3\t4\t5\t6\t7\t8\t9 << endl
#include <iostream> using namespace std; int main() { int a, b, c, max; cout<<a=;
#include <iostream> using namespace std; int main (int argc, char* const argv[]) { int
#include <iostream> using namespace std; class A{ int b; public: A(){ cout<<Constructor for class
#include<iostream> using namespace std; class Abc { public: int a; Abc() { cout<<Def cstr
#include <iostream> using namespace std; int main(void){ int size = -2; int* p =
Example: #include <iostream> using namespace std; int main() { wchar_t en[] = LHello; wchar_t
The following code #include <iostream> using namespace std; int main() { const char* const
#include iostream #include string using namespace std; #define AA(bb) \ string(::##bb); int main (int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.