Skip to content

Instantly share code, notes, and snippets.

@jesuscmadrigal
Created November 23, 2017 18:32
Show Gist options
  • Save jesuscmadrigal/d390e306a123356def022c4a954fe6e2 to your computer and use it in GitHub Desktop.
Save jesuscmadrigal/d390e306a123356def022c4a954fe6e2 to your computer and use it in GitHub Desktop.
#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