Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- float factorial(float x);
- float func(float fact_value);
- int is_equal(float val1, float val2, float eps);
- int main()
- {
- float eps;
- float sum=0, i=1;
- printf("Enter epsilon: ");
- scanf("%f", &eps);
- while (is_equal(func(i), func(i-1), eps) != 1)
- {
- sum += func(i);
- // printf("%f is an element and %f is sum\n", func(i), sum);
- i++;
- }
- printf("Total sum is %f ", sum);
- getch();
- return 0;
- }
- float factorial(float x)
- {
- float fact_value;
- for (int i = 1; i <= x; fact_value *= i++);
- if (x == 0)
- fact_value = 1;
- return fact_value;
- }
- float func(float fact_value)
- {
- float func_value;
- return func_value = 1 / fact_value;
- }
- int is_equal(float val1, float val2, float eps)
- {
- int result;
- result = fabs(val1 - val2) < eps;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement