CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: arrays mininum

  1. #1
    Join Date
    Jun 2011
    Posts
    21

    Question arrays mininum

    Code:
    #include <iostream>
    using namespace std;
    
    void printarray (int arg[], int length)
    //printarray will print the numbers in the array
     {
      for (int n=0; n<length; n++)
        cout << arg[n] << " ";
      cout << "\n";
    }
    int MinimumEntry (int a[], int n)
    {
      if (n==1) return a[0];
      int result = MinimumEntry(a+1, n-1); // note the a+1 and corrected name
      if (a[0] < result)
        return a[0];
      else
        return result;
    }
    
    int main ()
    {
      int firstarray[] = {3,2,3,-4,5,6};
      int secondarray[]={ 3,2,3,4,5,6};
      int thirdarray[]={3,2,3,-4,5,6};
      cout<<"First Array is: ";
      cout<<endl;
      printarray (firstarray,6);
      cout<<"Second Array is:";
      cout<<endl;
      printarray(secondarray,6);
      cout<<"Third Array is:";
      cout<<endl;
      printarray(thirdarray,6);
      cout<<endl;
      cout<<"sum of First Array =";
      cout<<endl;
      MininumEntry(firstarray,6);
    
    return 0;
    }
    what is wrong with MininumEntry???
    thanks

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: arrays mininum

    Quote Originally Posted by ryamjones View Post
    what is wrong with MininumEntry???
    thanks
    Have you used your compiler's debugger? If you wrote the code, then you must (not should, but must) be able to debug yourself if something is not correct.

    Visual C++ has a debugger, and you should be using it at all times when you want to figure out why something doesn't work.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; July 20th, 2011 at 07:10 PM.

  3. #3
    Join Date
    May 2000
    Location
    Armenia
    Posts
    201

    Re: arrays mininum

    what is wrong with MininumEntry???
    At least the name itself.
    According to its name in the definition it should be MinimumEntry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured