Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int silnia (int n)
  7. {
  8. if (n == 0) return 1;
  9. else return n*silnia(n-1);
  10. }
  11.  
  12. int main(){
  13.  
  14. double x;
  15. cout << "Podaj x\n";
  16. cin >> x;
  17.  
  18. double eps = 0.0001;
  19. double sum = 0.0;
  20. double prev = 0.0;
  21. int n = 0;
  22.  
  23. while(fabs(sum - prev) > eps){
  24. prev = sum;
  25. sum += (pow(-1, n) / (silnia(2*n))) * pow(x, 2*n);
  26. n++;
  27. cout << sum << endl;
  28. }
  29.  
  30. cout << sum << endl;
  31.  
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement