Advertisement
Josif_tepe

Untitled

Mar 1st, 2024
830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main() {
  5.     int n;
  6.     cin >> n;
  7.     int niza[n];
  8.     for(int i = 0; i < n; i++) {
  9.         cin >> niza[i];
  10.     }
  11.    
  12.     double sum = 0.0;
  13.     for(int i = 0; i < n; i++) {
  14.         sum += niza[i];
  15.     }
  16.     sum /= n;
  17.     double najbliska_razlika = 2000000000;
  18.     int kukja;
  19.    
  20.     for(int i = 0; i < n; i++) {
  21.         if(fabs(sum - niza[i]) < najbliska_razlika) {
  22.             najbliska_razlika = fabs(sum - niza[i]);
  23.             kukja = niza[i];
  24.         }
  25.     }
  26.     cout << kukja << endl;
  27.     return 0;
  28. }
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement