Advertisement
Guest User

Untitled

a guest
May 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5.  
  6. int M[10];
  7. int k=0, r, elem1, elem2, r_diff=-1, diff, max_diff=-1;
  8. cout << "Введите число R: ";
  9. cin >> r;
  10. cout << "Введите 10 элементов массива: " << endl;
  11. for (int i=0; i<10; i++){
  12. cin >> M[i];
  13. }
  14. cout << "Сформировано" << endl;
  15.  
  16. for (int i=0; i<10; i++){
  17. for (int j=i+1; j<10; j++){
  18.  
  19. diff = abs( M[i] - M[j] );
  20. r_diff = abs( r - diff );
  21.  
  22. if(r_diff > max_diff){
  23. max_diff = r_diff;
  24. elem1 = M[i];
  25. elem2 = M[j];
  26. }
  27.  
  28. }
  29. }
  30. cout << "разность c R: " << max_diff << endl;
  31. cout << "элементы: " << elem1 << " " << elem2 << endl;
  32.  
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement