Advertisement
Guest User

Untitled

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