Skip to content

Instantly share code, notes, and snippets.

@cohalz
Created October 1, 2013 04:42
Show Gist options
  • Save cohalz/6773950 to your computer and use it in GitHub Desktop.
Save cohalz/6773950 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
long fact(int n){
if (n <= 1) {
return 1L;
} else {
return n * fact(n -1);
}
}
double _pow(double x,int n){
int i;
for(i=1;i<n;i++){
x *= x;
}
return x;
}
int main(){
int n,i;
double x;
double sum = 0.0;
printf("n = ");
scanf("%d", &n);
printf("x = ");
scanf("%lf", &x);
for(i=0;i<=n;i++){
sum += (fact(2*i) * _pow(x,2*i+1)) / (_pow(4,i) * _pow(fact(i),2) * (2*i+1));
}
printf("%lf\n",M_PI/2 - sum);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment