Created
April 12, 2017 23:02
-
-
Save MattMSumner/a81ca14fa5d1ed65acf1862206b294e0 to your computer and use it in GitHub Desktop.
Recursion in c++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int findLargest(int array[]) | |
{ | |
int arrayLength = sizeof(array)/sizeof(array[0]); | |
int firstElement = array[0]; | |
int newArray[] = // This needs to be a new array without the original array's first element. | |
if (arrayLength == 1) { | |
return max(firstElement, newArray[0]) | |
} else { | |
return max(firstElement, findLargest(newArray)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This probelm can also be solved without using the TempArray/NeewArray
// Recursive programme to print the maximum element in the Array
`
int findmax(int arr[], int size)
{
}
int main()
{
}
`