Skip to content

Instantly share code, notes, and snippets.

@aruneko
Last active December 13, 2016 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aruneko/0cf0a72d46b713965dff963b9eaafacb to your computer and use it in GitHub Desktop.
Save aruneko/0cf0a72d46b713965dff963b9eaafacb to your computer and use it in GitHub Desktop.
#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