Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4.  
  5. float factorial(float x);
  6. float func(float fact_value);
  7. int is_equal(float val1, float val2, float eps);
  8.  
  9. int main()
  10. {
  11. float eps;
  12. float sum=0, i=1;
  13. printf("Enter epsilon: ");
  14. scanf("%f", &eps);
  15. printf("%f \n", func(5)-func(2));
  16. while (fabs(func(i)-func(i-1))<= eps)
  17. {
  18. sum+=func(i);
  19. i++;
  20. }
  21. printf("Total sum is %f ", sum);
  22. getch();
  23. return 0;
  24. }
  25.  
  26. float factorial(float n)
  27. {
  28. if (n == 0 || n == 1) return 1;
  29. return (n * factorial(n - 1));
  30. }
  31.  
  32. float func(float x)
  33. {
  34. return 1 /factorial(x);
  35. }
  36.  
  37. int is_equal(float val1, float val2, float eps)
  38. {
  39. int result;
  40. result = fabs(val1 - val2) < eps;
  41. return result;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement