Created
November 23, 2017 18:32
-
-
Save jesuscmadrigal/d390e306a123356def022c4a954fe6e2 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<math.h> | |
using namespace std; | |
double factorial (int x) | |
{ | |
double factorial=1; | |
for(int i=1.; i<x; i++) | |
{ | |
factorial=factorial*i; | |
} | |
return factorial; | |
} | |
double calculate_e (int precision) | |
{ | |
double e=0; | |
for(int i=1; i<25; i++) | |
{ | |
e=e+1/factorial(i); | |
} | |
cout.precision(precision); | |
cout<<fixed<<e<<endl; | |
} | |
int main() | |
{ | |
int number; | |
cout<<"Ingresa el numero de decimales con los cuales quieres calcular e: "<<endl; | |
cin>>number; | |
calculate_e(number); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment