Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. vector <int> numbers;
  8.  
  9. int main(){
  10.  
  11. int arraySize;
  12. cin >> arraySize;
  13.  
  14. int numbers [arraySize];
  15.  
  16. for (int i = 0; i < arraySize; i++){
  17.     cin >> numbers [i];
  18. }
  19.  
  20. int absRecord = INT8_MAX;
  21. int absMin;
  22.  
  23. for (int i = 0; i < arraySize; i++){
  24.     for (int k = 0; k < arraySize; k++){
  25.  
  26.         if (i != k){
  27.             absMin = abs (numbers [i] - numbers [k]);
  28.         }
  29.  
  30.         if (absMin < absRecord ){
  31.             absRecord = absMin;
  32.         }
  33.     }
  34. }
  35.  
  36. if (arraySize > 1){
  37. cout << absRecord << endl;
  38. } else {
  39.     cout << 0 << endl;
  40. }
  41.  
  42.  
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement