Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdio.h>
- #include <conio.h>
- #include <iostream>
- #include <math.h>
- #include <ctime>
- using namespace std;
- struct point
- {
- int x;
- int y;
- };
- double Long(point &A, point &B);
- int main(void)
- {
- point *mas;
- int n,x,y;
- int line;
- int k = 0;
- int PointA = 0;
- int PointB=1;
- int a = 1;
- cout << "Vvidite ckolko budet koordinat = ";
- cin >> n;
- srand(time(NULL));
- if (n < 1)
- {
- n = 10;
- mas = new point[n];
- for (int i = 0; i < n; i++)
- {
- mas[i].x = rand() % 201 - 100;
- mas[i].y = rand() % 201 - 100;
- }
- }
- else
- {
- mas = new point[n];
- for (int i = 0; i < n; i++)
- {
- cout << "mas[" << i << "] = ";
- cin >> mas[i].x >> mas[i].y;
- }
- }
- for (int i = 0; i<n; i++)
- {
- cout << mas[i].x << " " << mas[i].y << "\n";
- }
- line = Long(mas[1], mas[2]);
- for (int i = 0; i<n; i++)
- {
- for (int j = a; j<n; j++)
- {
- k++;
- if (line < Long(mas[i], mas[j]))
- {
- line = Long(mas[i], mas[j]);
- PointA = i;
- PointB = j;
- }
- }
- a++;
- }
- x = (mas[PointA].x+ mas[PointB].x)/2;
- y = (mas[PointA].y + mas[PointB].y) / 2;
- cout << "\nKoordinatji tochki: (" << x << ";"<<y<<")"<< endl;
- cout << "\nKolichestvo sravnenij: " << k << endl;
- _getch();
- return 0;
- }
- double Long(point &A, point &B)
- {
- return sqrt(pow(B.x - A.x, 2) + pow(B.y - A.y, 2));
- }
Advertisement
Add Comment
Please, Sign In to add comment