BushMaster
January 1st, 2007, 06:05 AM
Hi guys, seasons greetings.
I am doing a little exercise on recursion. This piece of code lists an array in reverse order.
//Chapter 6: Programming Exercises Question 12
#include <iostream>
using namespace std;
int func (int x[], int lo, int hi);
int main()
{
int intArray[] ={1,2,3,4,5,6,7,8,9,10};
int length = 10;
int low = 0;
int high = 9;
cout<<func(intArray, low, high);
return 0;
}
int func (int x[], int lo, int hi)
{
if(lo <= hi)
{
func( x, lo+1, hi);
cout<<x[lo]<<" ";
}
}
It works fine. Just when I get the print out, it has a number at the end.
eg,10 9 8 7 6 5 4 3 2 1 4416752
what is the "4416752"? where is it coming from? even if i tell it only tp print one number from the array, it appears after the numeber.
any ideas?
Ian
I am doing a little exercise on recursion. This piece of code lists an array in reverse order.
//Chapter 6: Programming Exercises Question 12
#include <iostream>
using namespace std;
int func (int x[], int lo, int hi);
int main()
{
int intArray[] ={1,2,3,4,5,6,7,8,9,10};
int length = 10;
int low = 0;
int high = 9;
cout<<func(intArray, low, high);
return 0;
}
int func (int x[], int lo, int hi)
{
if(lo <= hi)
{
func( x, lo+1, hi);
cout<<x[lo]<<" ";
}
}
It works fine. Just when I get the print out, it has a number at the end.
eg,10 9 8 7 6 5 4 3 2 1 4416752
what is the "4416752"? where is it coming from? even if i tell it only tp print one number from the array, it appears after the numeber.
any ideas?
Ian