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 || x<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 - log(x)),((double)(clock() - time))/CLOCKS_PER_SEC);
- return 0;
- }
- #include <math.h>
- #include "f.h"
- double fun(double x,double eps)
- {
- int counter1 = 0,counter2 = 0,i;
- double res = 0,k = 1;
- while(x >= 1)
- {
- x /= 2;
- counter1 ++;
- }
- while(x <= 0.1)
- {
- x *= 2;
- counter2 ++;
- }
- x -= 1;
- for(i = 1;fabs(k/(1+x))>eps;i++)
- {
- k *= x;
- if(i%2 == 0)
- res -= k/i;
- else
- res += k/i;
- }
- res += (counter1*M_LN2 - counter2*M_LN2);
- 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