Question: Please help me to write a below C++ program in MIPS - to find maximum element in the array C++ Code // Recursive C++ program
Please help me to write a below C++ program in MIPS - to find maximum element in the array
C++ Code
// Recursive C++ program to find maximum
#include
using namespace std;
// function to return maximum element using recursion
int findMaxRec(int A[], int n)
{
// if n = 0 means whole array has been traversed
if (n == 1)
return A[0];
return max(A[n-1], findMaxRec(A, n-1));
}
// driver code to test above function
int main()
{
int A[] = {1, 4, 45, 6, -50, 10, 2};
int n = sizeof(A)/sizeof(A[0]);
cout << findMaxRec(A, n);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
