1234567891011121314151617181920212223242526272829303132 |
- #include <stdio.h>
- #include <math.h>
- double calculate_sin(double x, int n) {
- double result = 0.0;
- double term = x;
- double sign = 1.0;
-
- int i;
- for (i = 1; i <= n; ++i) {
- result += sign * term;
- sign = -sign;
- term *= x * x / ((2 * i) * (2 * i + 1));
- }
- return result;
- }
- int main() {
- double x;
- int n;
- scanf("%lf %d", &x, &n);
- double sin_x = calculate_sin(x, n);
- printf("%.8lf\n", sin_x);
- return 0;
- }
|