Advertisement
Guest User

tailor

a guest
Sep 18th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. long fact(int n) { //функция вычисления факториала
  7. if (n==0) return 1; //условие выхода из рекурсии
  8. else
  9. return n*fact(n-1); //начало рекурсии
  10. }
  11.  
  12. int main() {
  13. int n;
  14. double y, s, sn;
  15. cout << "x y F(x) n"; //шапка таблицы
  16. for (float x=0;x<=1;x+=0.2) //перебор заданных х
  17. {
  18. y=cos(x);
  19. s=0; n=0;
  20. do { //цикл для вычисления S(x) с заданной погрешностью
  21. sn=pow(-1,n)*pow(x,2*n)/fact(2*n);
  22. s+=sn;
  23. n++;
  24. }
  25. while (abs(sn)>0.000001); //погрешность - условие выхода из цикла
  26.  
  27. cout << endl << x << " " << y << " " << s << " " << n; //вывод таблицы
  28. }
  29.  
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement