Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- #include "f.h"
- int main(void)
- {
- double x,res,eps;
- clock_t time;
- printf("x and EPS ");
- if((scanf("%lf",&x)!=1) || scanf("%lf",&eps)!=1)
- {
- fprintf(stderr,"Can not read x or eps\n");
- return ERROR_READ;
- }
- if(eps<0)
- {
- fprintf(stderr,"Incorrect EPS!\n");
- return ERROR_READ;
- }
- time = clock();
- res = fun(x,eps);
- printf("RESULT: %lf\nCalculation error: %lf\nTIME: %lf\n",res,fabs(res - exp(x)),((double)(clock() - time))/CLOCKS_PER_SEC);
- return 0;
- }
- #include <math.h>
- #include "f.h"
- double fun(double x, double eps)
- {
- int i,flag = 0;
- double res = 1,k = 1;
- if(x<0)
- {
- flag++;
- x *= -1;
- }
- for(i = 1;k>eps;i++)
- {
- k *= x/i;
- res += k;
- }
- if(flag%2 == 1)
- res = 1/res;
- return res;
- }
- #ifndef F_H
- #define F_H
- double fun(double x0, double eps);
- #define ERROR_READ 1
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement