Skip to content

Instantly share code, notes, and snippets.

@magmel48
Last active September 14, 2015 18:37
Show Gist options
  • Save magmel48/13eb7aa3b6c56b921211 to your computer and use it in GitHub Desktop.
Save magmel48/13eb7aa3b6c56b921211 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
#include <conio.h>
#define PI 3.1415926
double mysin(double n)
{
if (n >= 0) {
while (n >= 1) {
n -= 2 * PI;
}
}
else {
while (n <= -1) {
n += 2 * PI;
}
}
double e = 0.001;
double res = 0;
double el = n;
int i = 1;
int c = 1;
while (abs(el) >= e) {
if (c % 2 != 0) {
res += el;
}
else {
res -= el;
}
i += 2;
++c;
el /= i * (i - 1);
el *= n * n;
}
return res;
}
int main(void) {
printf("%lf", mysin(100));
getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment