Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /* Exponent calculating with eps accuracy, 0<eps<1 */
- int fact(int num);
- int cntNum(double num);
- main()
- {
- double eps, summand = 1.0, exp = 0.0;
- int n = 0, size;
- puts("enter epsilon's value");
- scanf("%g", &eps);
- while (summand > eps) {
- summand = 1.0 / fact(n);
- exp += summand;
- ++n;
- }
- size = cntNum(eps);
- printf("%.*g\n", size, exp);
- return 0;
- }
- int fact(int num)
- {
- int i;
- long factNum = 1;
- for (i = 1; i <= num; ++i)
- factNum *= i;
- return factNum;
- }
- int cntNum(double num)
- {
- int i = 0;
- while (num != 1) {
- num *= 10;
- ++i;
- }
- return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment