|
-
July 20th, 2011, 06:55 PM
#1
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
-
July 20th, 2011, 07:07 PM
#2
Re: arrays mininum
 Originally Posted by ryamjones
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.
-
July 20th, 2011, 08:49 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|