Please write the program in C The value of the mathematical

Please write the program in C

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 c by computing the value of 1+1/1! + 1/2! + 1/3! + ... + 1/n! where n is an integer entered by the user. Sample input: 3 Sample output: 2.666667

Solution

Hi buddy, please find the below C program. I\'ve added comments for your better understanding

#include <stdio.h>
#include <math.h>

int main(void) {
   // your code goes here
   int n;
   printf(\"Enter the value of n\ \");
   scanf(\"%d\",&n);
   //This array stores the factorials of a number
   int fact[n+1];
   //Factorial of 0 is 1
   fact[0] = 1;
   //Calculating the factorials of all numbers in this loop. Factorial of n = n*(factorial of n-1)
   for(int i=1;i<=n;i++){
   fact[i] = fact[i-1]*i;
   }
   double ans = 1;
   //Calculating the answer
   for(int i=1;i<=n;i++){
   ans = ans + (1.00/fact[i]);
   }
   printf(\"%lf\",ans);
   return 0;
}

Please write the program in C 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 tha

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site