fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int maxi(int sizee, int next, int scores[], int maxx)
  6. {
  7. if ( sizee == next )
  8. return maxx;
  9.  
  10. if (scores[maxx] < scores[next])
  11. maxx=next;
  12.  
  13. return maxi(sizee, next+1, scores, maxx);
  14. }
  15.  
  16. int maxi(int sizee, int scores[])
  17. {
  18. return maxi(sizee, 0, scores, 0);
  19. }
  20.  
  21. int main()
  22. {
  23. int arr[] = {5,2,8,1,4};
  24. int len = sizeof(arr) / sizeof(int);
  25.  
  26. cout << "Index of the maximum element is: " << maxi(len, arr) << endl;
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Index of the maximum element is: 2