Advertisement
informaticage

McLaurin Euler approximation

May 31st, 2021
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. double euler_approximation(unsigned int iterations);
  4.  
  5. int main(void) {
  6.   int iterations_amount;
  7.   scanf("%d", &iterations_amount);
  8.  
  9.   printf("Result: %lf", euler_approximation(iterations_amount));
  10.   return 0;
  11. }
  12.  
  13. double euler_approximation(unsigned int iterations) {
  14.   unsigned int fact = 1; // 0!
  15.   double euler = 0;
  16.   for (size_t i = 1; i <= iterations; i++) {
  17.     euler += 1.0 / fact;
  18.     fact *= i;
  19.   }
  20.   return euler;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement