fork download
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. void pntTheArray(int *(arrName), unsigned sizeOfArray);//Version of the first function, using pointers
  8.  
  9. int main()
  10. {
  11. int someArr[3]={7,2,6};
  12. int pointerArray[5]={7,6,5,4,10};
  13.  
  14. pntTheArray(someArr, 3);//Example of the function with the pointers
  15. }
  16.  
  17.  
  18. void pntTheArray(int *arrName, unsigned sizeOfArray){
  19. int max = 0;
  20. int min = 999999;
  21. for (int x = 0;x<sizeOfArray;x++){
  22. cout << "i: " << x << " val: " << *(arrName+x) << "\n";
  23. if (*(arrName+x)>max){
  24. max = *(arrName+x);
  25. }
  26. if(*(arrName+x)<min){
  27. min = *(arrName+x);
  28. }
  29. }
  30. cout<<"The maximum element minus the the minimum element is: "<<(unsigned)(max-min)<<endl;
  31. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
i: 0 val: 7
i: 1 val: 2
i: 2 val: 6
The maximum element minus the the minimum element is: 5