Advertisement
Anik_Akash

min max find return an array

Oct 7th, 2021
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace    std;
  3.  
  4. #define flush                    cin.ignore(numeric_limits<streamsize>::max(),'\n')
  5. #define FASTERIO                 ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6. #define NL                       cout<<'\n';
  7. #define pi                       acos(-1.0) //3.1415926535897932384626
  8. #define pb                       push_back
  9. #define mk                       make_pair
  10. #define mx                       1000005
  11. #define EPS                      1e-10
  12. #define dpoint(x)                fixed<<setprecision(x)
  13. # define my_sizeof(type) ((char *)(&type+1)-(char*)(&type))
  14. typedef long long int            ll;
  15. typedef double                   dl;
  16. typedef unsigned long long int   ull;
  17.  
  18. int *find_min_mx(int *arr, int n){
  19.     int min=INT_MAX, max = 0;
  20.     for(int i=0; i<n; i++){
  21.         if(arr[i]<min)min = arr[i];
  22.         if(arr[i]>max)max = arr[i];
  23.         arr[0] = min;
  24.         arr[1] = max;
  25.     }
  26.     return arr;
  27. }
  28.  
  29. int main() {
  30.  
  31. #ifdef anikakash
  32.     clock_t tStart = clock();
  33.     freopen("input.txt", "r", stdin);
  34.     freopen("tmp.txt", "w", stdout);
  35. #endif
  36.  
  37.     FASTERIO; //cmt when use scanf & printf ;
  38.  
  39.     int n; cin>>n;
  40.     int arr[n];
  41.     for(int i=0; i<n; i++)cin>>arr[i];
  42.  
  43.     int *ptr = find_min_mx(arr,n);
  44.     cout<<"Max value "<<*(ptr)<<endl;
  45.     cout<<"Min value "<<*(ptr+1)<<endl;
  46.  
  47.  
  48. #ifdef anikakash
  49.     fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  50. #endif
  51.  
  52.     return 0;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement