# Euler number

--Originally published at TC1017 Programing Curse

In this assignment i had to estimate the mathematical constant e. I create a function called calculuate_e which receives one parameter called precision that should specify the number of decimal points of accuracy.

There is the code

#include <iostream>
#include <math.h>
using namespace std;

int getFactorial(int num){
if (num == 1 || num == 0)
{
return 1;
}
else
{
return num*getFactorial(num-1);
}
}
float euler_calc(float par){
float num = 0.0, result=0.0;
do{
result += 1.0/(getFactorial(num));
num = num + 1;
} while(num <= par);
return result;
}

int main(){
float par, result, num=0.0;
cout << “Give me the parameter ” << endl;
cin >> par;
cout << “The answer is ” << euler_calc(par) << endl;

return 0;
}

image taken from http://digg.com/video/eulers-constant-explained

# WSQ 12 “NÚmer de Euler”

--Originally published at blog de Horacio

wat to do:

In this assignment you will estimate the mathematical constant e. You should create a function called calculuate_e which receives one parameter called precision that should specify the number of decimal points of accuracy.

Numero de Euler:

El número e es un número irracional famoso, y es uno de los números más importantes en matemáticas.

Las primeras cifras son:

2,7182818284590452353602874713527 (y sigue…)

Se lo suele llamar el número de Euler por Leonhard Euler

e es la base de los logaritmos naturales (inventados por John Napier). Por otra parte los logaritmos comunes tienen base 10.

sources:

https://foro.hackxcrack.net/index.php?PHPSESSID=ornujgai9nitgqh8b2v8tc0630

code on GitHub:

# e=2.71828182845904523536…

I was a little confused about this, but this classmate’s blog help me a lot, he has very good codes!

Sorry again, I’m a a little pressed with time so I’m not going to explained it. Actually it’s simple, I’m going to leave this link it explained very well and give some examples, I hope it will be useful.

The libraries that I used for this program was the <iostream> & <iomanip>

# Estimating e

--Originally published at savhprograming

En este programa nos piden la forma de poder imprimir la constante “e” pero se le puede dar al usuario la opcion que elijir cuantas cifras debe tener el numero. Por ejemplo
cout<<"cuantas cifras significativas quieres usar? ";
cin>>cifra;
cout<<"el valor con "<<cifra<<" cifras es de ";cout<<e(cifra)<<endl;

cuantas cifras significativas quieres usar? 5
el valor con 5 cifras es de 2.71667

el código que se creó fue el siguiente:

j

# include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
float nfactorial(int n){
float fact;
if(n==0){
return 1;
}
else {return n*nfactorial(n-1);}
}
float e (float cifra)
{
float x, e=1;
for (int i =1; i<= cifra; i++) //nos imprimira las cifras n del numero
{
e+=1/nfactorial (i);
}
cout <<fixed<<setprecision (cifra);
return e;
}
int main()
{
float cifra;
cout<<"cuantas cifras significativas quieres usar? ";
cin>>cifra;
cout<<"el valor con "<<cifra<<" cifras es de ";cout<<e(cifra)<<endl;

return 0;
}

# Estimating e

--Originally published at my programming blog

So what we needed to do was a function that had just one parameter and to estimate the value of e.

What I did was:

1. I did first a float function where I calculated the factorial.
2. Then In the second function my para meter was precision which is the number of decimal points I want in my result.
3. Inside the function I only did a for loop where the condition was that while the int i was smaller or equal to precision this would happen : e will be equal to e plus 1/factorial of i.
4. Then the function will cout (BUT IT WILL NOT PRINT ANYTHING) first it says fixed, which I used to start counting the precision form the decimal point, and the I used the function setprecision from the library “iomanip”. and at the end my function will return the value of e.
5. Finally in my int main I just ask the user for the precision and then I call my functions with parameter that my user gave me.

My code in Github: https://gist.github.com/mariasantoyodl/2cb288d17ecc951b8349e226d651a36a

# #WSQ12

--Originally published at OlafGC / Class #TC1017

This is a video that will help you calculate euler’s number, which is an irrational number… I’m having a little trouble with the function because it’s totally ignoring the precision (which is the number that the user gives, but it does calculate euler’s number correctly.

Here is the code:

#include <iostream>
#include <cmath>
using namespace std;

float factorial(int n)
{
if(n==0)
{
return 1;
}
else
{
return n*factorial(n-1);
}
}

float calculate_e(float precision)
{
float e=1;
float previous;
int i=1;

do
{
previous=e;
e=e+1/(factorial(i));
cout<<e<<endl;
i++;
} while(abs (e-previous)>precision);
return e;
}

int main()
{
float precision;
cout<<“How many decimals of accuracy do you want? “;
cin>>precision;
cout<<“The estimation of e with “<<precision<<” decimal points is: “<<calculate_e(precision)<<endl;
return 0;
}

# Homework 12: Estimating e

--Originally published at Let&#039;s CODE

This program will be capable of estimate the value of “Euler’s number” (e) and the user will give the accuracy expressed as a number of decimals. To calculate e, I declared three variables. One of them saves tha value of e, another counts each executation of the loop, and the last one (x), in each ocassion … Continue reading Homework 12: Estimating e