Kwwiker

Untitled

Oct 15th, 2020
123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * ДЗ 3 Задача "Ссуда"
  3. */
  4. void getProcent() {
  5.     double s, m, left, right, middle;
  6.     int n;
  7.     left = 0;
  8.     middle = 50;
  9.     right = 100;
  10.     cin >> s >> m >> n;
  11.     while (s * (middle/100) * pow(1 + (middle / 100), n) / (12 * (pow(1 + (middle / 100), n) - 1)) != m) {
  12.         if (s * (middle / 100) * pow(1 + (middle / 100), n) / (12 * (pow(1 + (middle / 100), n) - 1)) > m) {
  13.             right = middle;
  14.             middle = (left + middle) / 2;
  15.         }
  16.         else if (s * (middle / 100) * pow(1 + (middle / 100), n) / (12 * (pow(1 + (middle / 100), n) - 1)) < m) {
  17.             left = middle;
  18.             middle = (middle + right) / 2;
  19.         }
  20.     }
  21.     cout << middle;
  22. }
RAW Paste Data