Last active
September 14, 2015 18:37
-
-
Save magmel48/13eb7aa3b6c56b921211 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> | |
#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