limpingricky

tacke

Nov 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <math.h>
  2. #include <iostream>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. double fMax(int x[], int y[], int n, int poc);
  8.  
  9. void print(int arr[], int n);
  10.  
  11. int main() {
  12.     int n;
  13.     cout << "n:" << endl;
  14.     cin >> n;
  15.  
  16.     int x[n], y[n];
  17.  
  18.     for(int i = 0; i < n; i++){
  19.         cout << "x  y" << endl;
  20.         cin >> x[i] >> y[i];
  21.     }
  22.  
  23.     cout << x;
  24.     print(x, n);
  25.  
  26.     cout << y;
  27.     print(y, n);
  28.    
  29.     int koo = 0;
  30.     double max = 0, max1 = 0;
  31.    
  32.     for(int i = 0; i < n; i++){
  33.         max1 = fMax(x, y, n, i);
  34.         if(max1 > max){
  35.             max = max1;
  36.             koo = i;
  37.         }
  38.     }
  39.    
  40.     cout << "koordinata " << koo << endl;
  41.  
  42.     return 0;
  43. }
  44.  
  45. double fMax(int *x, int *y, int n, int poc) {
  46.     double max = 0;
  47.     double max1 = 0; //hipotenuza trougla
  48.     int l, r; //katete trougla
  49.  
  50.     for(int i = poc; i < n; i++){
  51.         l = abs(y[poc] - y[i]); // kateta po y
  52.         r = abs(x[poc] - x[i]); // kateta po x
  53.  
  54.         max1 = sqrt(pow(l, 2) + pow(r, 2));
  55.         max = (max1 > max)? max1 : max;
  56.     }
  57.  
  58.     return max;
  59. }
  60.  
  61. void print(int *arr, int n) {
  62.     for(int i = 0; i < n; i++){
  63.         cout << arr[i] << " ";
  64.     }
  65.     cout << endl;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment