The question are with reference to the C Programming Language Write a recursive
ID: 3751255 • Letter: T
Question
The question are with reference to the C Programming Language
Write a recursive function recursiveMaximum that takes an integer array and the array size and returns the largest element in the array. The function should stop processing and return when it receives an array of one element.
Here, you only need to do the following:
(b1) Write the function prototype
(b2) Show how the function will be called
(b3) Write the function definition for the function
Explanation / Answer
#include // prototype int recursiveMaximum(int arr[], int size); int main() { // calling the function int arr[] = {4, 3, 5, 2, 4}; int max = recursiveMaximum(arr, 5); printf("Maximum number in array is %d ", max); return 0; } // function definition for the function int recursiveMaximum(int arr[], int size) { if(size == 1) { return arr[0]; } else { int max = recursiveMaximum(arr, size-1); if(arr[size-1] > max) { max = arr[size-1]; } return max; } }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.