Advertisement
Rehan_Rahman26

Function Related Problem 4

Oct 7th, 2021
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int Minv(int A[], int n)
  5. {
  6. if (n == 1)
  7. return A[0];
  8. return min(A[n-1], Minv(A, n-1));
  9. }
  10. int Maxv(int A[], int n)
  11. {
  12. // if n = 0 means whole array has been traversed
  13. if (n == 1)
  14. return A[0];
  15. return max(A[n-1], Maxv(A, n-1));
  16. }
  17. int main()
  18. {
  19. int A[] = {1, 4, 45, 6, -50, 10, 2};
  20. int n = sizeof(A)/sizeof(A[0]);
  21.  
  22. cout << "Your Aray's Max value is: " << Maxv(A, n) << endl;
  23. cout << "Your Aray's Max value is: " << Minv(A, n) << endl;
  24.  
  25. return 0;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement