Guest User

Untitled

a guest
Nov 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. main()
  2. {
  3. float k=0, x, u=(x*x)/2, r, s=u, es=1e-3;
  4. while (fabs(u)>=es)
  5. {
  6.  
  7. r=(pow(-1, k+1)*pow(x,k+2))/(k+1);
  8. u*=r;
  9. s+=u;
  10. k++;
  11. }
  12. cout<<"Sum = "<<s;
  13. getch();
  14. }
  15.  
  16. main()
  17. {
  18. int n=0, u=1;
  19. float eps=1e-3, s=u, s1, x;
  20. while (abs(u)>=eps)
  21. {
  22. n++;
  23. u=pow(-1,n)*n;
  24. s+=u;
  25. }
  26. s1=1/(1-x);
  27. if (fabs(s-s1)<=eps) cout<<"To4noe zna4enie";
  28. else cout<<"Neto4noe zna4enie";
  29. getch();
  30. }
  31.  
  32. const double eps = 1e-8;
  33.  
  34. double series(double x, double epsilon)
  35. {
  36. double term = x*x/2.0, sum = term;
  37. for(int k = 0; fabs(term) > epsilon; ++k)
  38. {
  39. sum += (term *= -x*(k+1)/double((k+2)*(k+3)));
  40. }
  41. return sum;
  42. }
  43.  
  44. int main(int argc, const char * argv[])
  45. {
  46. for(double x = -1.0; x <= 1.0; x += 0.1)
  47. {
  48. cout << fixed << setprecision(2) << setw(5) << x
  49. << setprecision(10) << setw(15) << series(x,eps) << endl;
  50. }
  51. }
  52.  
  53. const double eps = 1e-8;
  54.  
  55. double series(double x, double epsilon)
  56. {
  57. double term = 1.0, sum = term;
  58. while(fabs(term) > epsilon)
  59. {
  60. sum += term *= x;
  61. }
  62. return sum;
  63. }
  64.  
  65. int main(int argc, const char * argv[])
  66. {
  67. for(double x = -0.9; x <= 0.9; x += 0.1)
  68. {
  69. cout << fixed << setprecision(2) << setw(5) << x
  70. << setprecision(10) << setw(15) << series(x,eps)
  71. << setw(15) << (1.0/(1-x)) << endl;
  72. }
  73. }
Add Comment
Please, Sign In to add comment