Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5. typedef double (*TFun)(double);
  6. double fun1(double x);
  7. double Factorial(int k, double rez);
  8. void Out(TFun,double a,double b,double h);
  9. double fun2(double n,double x);
  10. int main()
  11. {
  12. double a, b, h;
  13. int n,kod;
  14. cout << "Input a: " << endl;
  15. cin >> a;
  16. cout << "Input b: " << endl;
  17. cin >> b;
  18. cout << "Input n: " << endl;
  19. cin >> n;
  20. cout << "Input h: " << endl;
  21. cin >> h;
  22. cout<< "Y(x) - 0 "<<endl;
  23. cout<< "S(x) - 1 "<<endl;
  24. cin>>kod;
  25. switch(kod)
  26. {
  27. case 0:
  28. {
  29. cout << " Y(x): "<<endl;
  30. Out(fun1,a,b,h);
  31. }break;
  32. case 1:
  33. {
  34. cout << " S(x): "<<endl;
  35. Out(fun1,a,b,h);
  36. }break;
  37. }
  38. }
  39. double fun2(double n,double x)
  40. {
  41. double summ=0,rez;
  42. int k;
  43. for (k = 0; k <= n; k++)
  44. {
  45. summ = 0;rez=1;
  46. rez= Factorial(k,rez);
  47. summ += pow((2 * x), k) / rez ;
  48. }
  49. return summ;
  50. }
  51.  
  52. void Out(TFun,double a,double b,double h)
  53. {
  54. double x;
  55. for (x = a; x <= b; x += h)
  56. {
  57. cout <<fun1(x)<<endl;
  58.  
  59. }
  60. }
  61.  
  62. double fun1(double x)
  63. {
  64. return exp (2 * x);
  65. }
  66.  
  67. double Factorial(int numb,double rez)
  68. {
  69. int i;
  70. for ( i = numb; i != 0; i -- )
  71. {
  72. rez = rez * numb;
  73. numb--;
  74. }
  75. return rez;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement