Created
April 15, 2015 03:18
-
-
Save samir96/d39fbe0f0af388c171aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
float factorial(double a){ | |
float con, acum=1.0; | |
for(con=2.0; con<=a; con++){ | |
acum=acum*con; | |
} | |
return acum; | |
} | |
float calculate_e(int p){ | |
float e=0.0, ant, v; | |
for (float n=0.0; n<=p; n++){ | |
ant=e; | |
e= e + (1.0/factorial(n)); | |
cout<<e<< endl; | |
cout <<endl; | |
if (ant == e){ | |
break; | |
} | |
} | |
v *= pow(10, p); | |
v = floor(v); | |
v /= pow(10, p); | |
return e; | |
} | |
int main () { | |
int p; | |
cout<<"Dame la precison de e "; cin >> p; | |
cout<<calculate_e(p); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment