The value of the mathematical constant e can be expressed as

The value of the mathematical constant e can be expressed as an infinite series e = 1 + 1/1! + 1/2! + 1/3! +... Write a program that approximates e by computing the value of 1 + 1/1! + 1/2! + 1/3! + ... + 1/n! where n is ail integer entered by the user. Sample input: 3 Sample output: 2.666667

Solution

#include<stdio.h>

int main (void)
{
int n,i,j;
float e=1.0, nFact=1;

printf(\"please enter the number\");
scanf(\"%d\", &n);

for( i =1; i<= n ; i++)
{
nFact*=i;
e = e + (1.0/ nFact);
}

printf(\"The value of \'e\' is : %f\", e);

return 0;
}

 The value of the mathematical constant e can be expressed as an infinite series e = 1 + 1/1! + 1/2! + 1/3! +... Write a program that approximates e by computin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site