-
-
Save limtbk/9c36d231320283fdac73eb693c90b685 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define abs(x) ((x)<0 ? -(x) : (x)) | |
double calc_prec(double x, double pr) | |
{ | |
double s = 0; | |
double n = 1; | |
double k = 1; | |
double xx = x; | |
if ((x > -1) && (x <= 1)) { | |
double a = xx / n; | |
while (abs (a) > pr) { | |
//printf("%f\n", s); | |
s = s + k * a; | |
xx = xx * x; | |
n = n + 1; | |
k = -k; | |
a = xx / n; | |
} | |
} | |
return s; | |
} | |
int main() | |
{ | |
printf("%f\n", calc_prec(0.5, 0.0001)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment