Advertisement
Trapov

Untitled

Mar 17th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     cout << "Type your N: " << endl;
  8.     int n;
  9.     cin >> n;
  10.     int* mas = new int[n];
  11.     int summ_of_mid = 0;
  12.     for (int i = 0; i<=n; i++)
  13.     {
  14.         mas[i] = rand();
  15.         cout << mas[i] << endl;
  16.         summ_of_mid += mas[i];  
  17.     }
  18.     cout << "Middle number is: " << (summ_of_mid /= n) << endl;
  19.     int best_n(0);
  20.     for (int i = 0; i<=n; i++)
  21.     {
  22.         float buf_d_b(0);
  23.         float buf_d = ((float)mas[i])/((float)summ_of_mid);
  24.         if (buf_d>buf_d_b)
  25.         {
  26.             buf_d_b = buf_d;
  27.             buf_d = 0;
  28.             best_n = mas[i];
  29.            
  30.         }
  31.     }
  32.     cout << "Your best number is: " << best_n << endl;
  33.     system("pause");
  34.     delete []mas;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement