Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- double fMax(int x[], int y[], int n, int poc);
- void print(int arr[], int n);
- int main() {
- int n;
- cout << "n:" << endl;
- cin >> n;
- int x[n], y[n];
- for(int i = 0; i < n; i++){
- cout << "x y" << endl;
- cin >> x[i] >> y[i];
- }
- cout << x;
- print(x, n);
- cout << y;
- print(y, n);
- int koo = 0;
- double max = 0, max1 = 0;
- for(int i = 0; i < n; i++){
- max1 = fMax(x, y, n, i);
- if(max1 > max){
- max = max1;
- koo = i;
- }
- }
- cout << "koordinata " << koo << endl;
- return 0;
- }
- double fMax(int *x, int *y, int n, int poc) {
- double max = 0;
- double max1 = 0; //hipotenuza trougla
- int l, r; //katete trougla
- for(int i = poc; i < n; i++){
- l = abs(y[poc] - y[i]); // kateta po y
- r = abs(x[poc] - x[i]); // kateta po x
- max1 = sqrt(pow(l, 2) + pow(r, 2));
- max = (max1 > max)? max1 : max;
- }
- return max;
- }
- void print(int *arr, int n) {
- for(int i = 0; i < n; i++){
- cout << arr[i] << " ";
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment