Guest User

Untitled

a guest
Jul 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /* Prints out a value of e until the order n */
  4. int main()
  5. {
  6.   /* Declare and initialize variables if necessary */
  7.   int number, i, j;
  8.   float e = 1.0f, fac_sum = 1.0f;
  9.  
  10.   /* Prompt the user to enter a number and scan it */
  11.   printf("Please enter a number: ");
  12.   scanf("%d", &number);
  13.  
  14.   /* Main for loop */
  15.   for (i = 1; i <= number; i++) {
  16.     /* Calculates the factorial of n */
  17.     for (j = number; j > 0; j--) {
  18.       fac_sum *= j;
  19.     }
  20.     e += 1.0f / fac_sum;
  21.     fac_sum = 1.0f;
  22.   }
  23.  
  24.   /* Print the value of e*/
  25.   printf("Your value of e is: %f", e);
  26.  
  27.   return 0;
  28. }
Add Comment
Please, Sign In to add comment