Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int length = 0;
  8.  
  9. cin >> length;
  10. const int len = length;
  11. int diff = 0;
  12. int arr[len] = {};
  13. int minValue = INT_MAX;
  14.  
  15. for(int i = 0; i < len; i ++){
  16. cin >> arr[i];
  17. }
  18.  
  19. for(int j = 0; j < len; j++){
  20. for(int k =j + 1; k < len; k ++){
  21. diff = abs(arr[j] - arr[k]);
  22. if(diff <= minValue){
  23. minValue = diff;
  24. }
  25. }
  26. }
  27. cout << minValue << endl;
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement