Skip to content

Instantly share code, notes, and snippets.

@samir96
Created April 15, 2015 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samir96/d39fbe0f0af388c171aa to your computer and use it in GitHub Desktop.
Save samir96/d39fbe0f0af388c171aa to your computer and use it in GitHub Desktop.
#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