fork(3) download
  1. #include <iostream>
  2. #include <limits.h>
  3.  
  4. int array[] = { 2, -5, 10, 4 };
  5.  
  6. int main() {
  7.  
  8. int max_v = INT_MIN;
  9. int max_i = 0;
  10.  
  11. for ( int i = 0; i < sizeof(array)/sizeof(array[0]); i++ )
  12. {
  13. if ( array[i] > max_v )
  14. {
  15. max_v = array[i];
  16. max_i = i;
  17. }
  18. }
  19.  
  20. printf( "The max value (%d) is at index %d.", max_v, max_i);
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 2684KB
stdin
Standard input is empty
stdout
The max value (10) is at index 2.