1234567891011121314151617181920212223242526272829 |
- #include <stdio.h>
- #include <math.h>
- double jiecheng(int num) {
- double result = 1.0;
- int i = 1;
- while (i <= num) {
- result *= i;
- i++;
- }
- return result;
- }
- int main() {
- double x, sinx = 0.0, term;
- int n;
- scanf("%lf %d", &x, &n);
- int i = 1;
- while (i <= n) {
- term = pow(-1, i - 1) * pow(x, 2 * i - 1) / jiecheng(2 * i - 1);
- sinx += term;
- i++;
- }
- printf("%.8lf", sinx);
- return 0;
- }
|