Last active
December 13, 2016 11:35
-
-
Save aruneko/0cf0a72d46b713965dff963b9eaafacb to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#include <math.h> | |
double fact_rev(int n) { | |
double result = 1.0; | |
for (int i = 1; i <= n; ++i) { | |
result *= 1.0 / i; | |
} | |
return result; | |
} | |
double my_cos(double x) { | |
double ans = 0; | |
for (int i = 0; i <= 20; ++i) { | |
ans += pow(-1, (double)i) * fact_rev(2 * i) * pow(x, 2 * (double)i); | |
} | |
return ans; | |
} | |
int main() { | |
printf("%f\n", my_cos(M_PI / 2)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment