Advertisement
JewishCat

22.Рек.Ряд

May 31st, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <cstdlib>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. double ryad(double a, double b);
  8. int main() {
  9.     double a = 1;
  10.     double b = 0.5;
  11.     cout << "Summa ryada: ";
  12.     cout << ryad(a, b);
  13.     system("pause");
  14.     return 0;
  15. }
  16. double ryad(double a, double b) {
  17.     double sum = 0;
  18.     double buf = -(a*b / 2);
  19.     a = b;
  20.     b = buf;
  21.     int i = 2;
  22.     do {
  23.         sum += buf;
  24.         buf = -(a*b / 2);
  25.         a = b;
  26.         b = buf;
  27.     } while (fabs(a) > fabs(b));
  28.     return sum;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement