Advertisement
helos3

lab1 c++

Oct 4th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <vcl.h>
  2. #include <iostream>
  3. #include <windows.h>
  4. #include <math.h>
  5. #include <stdio.h>
  6.  
  7. using namespace std;
  8.  
  9. int _tmain(int argc, _TCHAR* argv[])
  10. {
  11. SetConsoleCP(1251);
  12. SetConsoleOutputCP(1251);
  13.  
  14. int coord[100][2],max[2][2],n,i,j,m;
  15.  
  16. cout <<"Введите размерность плоскости (m) и количество точек для плоскости размером mxm через пробел. \n" << endl;
  17. scanf("%d %d", &m, &n);
  18. printf("Получившиеся точки: \n");
  19.  
  20. srand((unsigned int)time(NULL));
  21. for ( i=1; i <= n; i++) {
  22. for ( j=1; j <= 2; j++)
  23. coord[i][j]= rand() % m;
  24. printf ("%d ",coord[i][1]);
  25. printf ("%d",coord[i][2]);
  26. printf ("\n");
  27. }
  28.  
  29. max[1][1]=0;
  30. max[1][2]=0;
  31. max[2][1]=0;
  32. max[2][2]=0;
  33.  
  34.  
  35. for (i=1; i <= n; i++)
  36. for (j=1; j <= n; j++){
  37. if (abs(coord[i][1]-coord[j][1])+abs(coord[i][2]-coord[j][2])> abs(max[1][1]-max[2][1])+abs(max[1][2]-max[2][2])) {
  38. max[1][1]=coord[i][1];
  39. max[1][2]=coord[i][2];
  40. max[2][1]=coord[j][1];
  41. max[2][2]=coord[j][2];
  42. }
  43. }
  44. cout << "Координаты самых дальних точек \n" << max[1][1] << " " << max[1][2] << "\n" << max[2][1] << " " << max[2][2] << endl;
  45. system("pause");
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement