Guest User

Untitled

a guest
Feb 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. //a program that approximate e by computing values
  2. #include <stdio.h>
  3.  
  4. //factorial method
  5. float factorial(int n){
  6. if(n <= 1)
  7. return 1;
  8. else
  9. return n*factorial( n-1 );
  10. }
  11.  
  12. //while loop that checks if the factorial is less than the num given
  13. int i = 2;
  14. while((1/factorial(i)) < num){
  15. result = result + (1/factorial(i));
  16. i++;
  17. }
  18.  
  19. int main(void)
  20. {
  21. //initialise variables for use
  22. float num, result=2;
  23.  
  24. //scan for the number
  25. scanf("%f", &num);
  26.  
  27. //return the result with 5 decimals
  28. printf("%.5f\n", result);
  29.  
  30. //return result
  31. return 0;
  32. }
Add Comment
Please, Sign In to add comment